Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Flutter and app store releases

Firebase email sign-in reports invalid-credential for every failure

Your error

INVALID_LOGIN_CREDENTIALS2 more lines it can show

Fix it fast

Most common cause, 1 of 2

Email enumeration protection merges unknown email and wrong password

Handle invalid-credential as 'email or password is incorrect' and keep the old codes only as extra cases.

Fix
String signInMessage(FirebaseAuthException e) {
  switch (e.code) {
    case 'invalid-credential':
    case 'invalid-login-credentials': // older native SDKs
    case 'user-not-found':            // projects without protection
    case 'wrong-password':
      return 'Email or password is incorrect.';
    case 'user-disabled':
      return 'This account has been disabled.';
    case 'too-many-requests':
      return 'Too many attempts. Wait a moment and try again.';
    default:
      return 'Sign-in failed (${e.code}).';
  }
}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Firebase Auth answers a failed email sign-in with INVALID_LOGIN_CREDENTIALS, reported by FlutterFire as invalid-credential, when email enumeration protection is on. That is the default for projects created on or after 15 September 2023, and it hides whether the email or the password was wrong. Catch invalid-credential and show one combined message. Applies to firebase_auth 7.1 on Flutter 3.44+.

  • Applies to firebase_auth 7.1.0 (Dart 3.12+, Flutter 3.44 to 3.50.x), Firebase Authentication with email enumeration protection on
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print e.code for two attempts: an email that has no account, and a real account with a wrong password. Identical codes for both mean protection is on; a real account that fails even with the right password points to the second cause.

Run this first
for (final email in ['no-account@example.com', 'real.user@example.com']) {
  try {
    await FirebaseAuth.instance
        .signInWithEmailAndPassword(email: email, password: 'not-the-password');
  } on FirebaseAuthException catch (e) {
    debugPrint('$email -> ${e.code}');
  }
}

Then find the line you see in this list and open its fix:

  1. 1Email enumeration protection merges unknown email and wrong passwordBoth test attempts print invalid-credential, never user-not-found or wrong-password
  2. 2The account has no password because it was created with another providerThe user can sign in with Google, Apple or a phone number, and even the password they are sure of returns invalid-credential

What does the error look like?

  • INVALID_LOGIN_CREDENTIALS
  • invalid-credential
  • invalid-login-credentials

Cause 1 of 2

Email enumeration protection merges unknown email and wrong password

You seeBoth test attempts print invalid-credential, never user-not-found or wrong-password

Check

Firebase Auth returns INVALID_LOGIN_CREDENTIALS for invalid sign-ins when email enumeration protection is enabled, so nobody can probe which addresses have accounts. FlutterFire maps it to invalid-credential, and its API reference marks user-not-found and wrong-password as deprecated because protected projects stop sending them; older native SDKs used invalid-login-credentials. A switch written for the old codes falls through to its default branch.

Check
// which project is the app signed in to? open its Authentication
// settings, User actions: "Email enumeration protection (recommended)"
debugPrint(Firebase.app().options.projectId);

Fix

Handle invalid-credential as 'email or password is incorrect' and keep the old codes only as extra cases. Offer a password reset link next to the message. Switching protection off brings the separate codes back, but Google recommends keeping it on in every project.

Fix
String signInMessage(FirebaseAuthException e) {
  switch (e.code) {
    case 'invalid-credential':
    case 'invalid-login-credentials': // older native SDKs
    case 'user-not-found':            // projects without protection
    case 'wrong-password':
      return 'Email or password is incorrect.';
    case 'user-disabled':
      return 'This account has been disabled.';
    case 'too-many-requests':
      return 'Too many attempts. Wait a moment and try again.';
    default:
      return 'Sign-in failed (${e.code}).';
  }
}

Verify

A wrong password and an unknown email both show the combined message, and the right password signs the user in.

Verify
flutter run

Confirmed by docs.cloud.google.com

Did this fix it?

Cause 2 of 2

The account has no password because it was created with another provider

You seeThe user can sign in with Google, Apple or a phone number, and even the password they are sure of returns invalid-credential

Check

The firebase_auth reference lists an account with no password set among the reasons for wrong-password, and under protection that case also arrives as invalid-credential. It catches users who signed up with a Google or Apple button and later type the same email into the password form. Sign in with the original provider and print the provider IDs on the account: the password provider is missing.

Check
final user = FirebaseAuth.instance.currentUser;
debugPrint(user?.providerData.map((p) => p.providerId).join(', '));
debugPrint(EmailAuthProvider.PROVIDER_ID); // not in the list above

Fix

Point the user back to the provider they used. If they want a password as well, let them sign in with that provider first and then link an email credential to the same account.

Fix
final credential = EmailAuthProvider.credential(email: email, password: newPassword);
try {
  await FirebaseAuth.instance.currentUser?.linkWithCredential(credential);
} on FirebaseAuthException catch (e) {
  debugPrint(e.code); // provider-already-linked, credential-already-in-use, ...
}

Verify

providerData now includes the email provider, and after signing out the user can sign in with email and the new password.

Verify
await FirebaseAuth.instance.signOut();
await FirebaseAuth.instance
    .signInWithEmailAndPassword(email: email, password: newPassword);

Confirmed by firebase.google.com

Did this fix it?

How do I stop it coming back?

  • Write sign-in error handling around invalid-credential first and keep user-not-found and wrong-password only as fallbacks; older samples that branch on them alone never fire on a protected project.
  • Build the 'does this email have an account?' screen without asking Firebase: fetchSignInMethodsForEmail was removed from firebase_auth for security reasons, and protected projects return no sign-in methods anyway.
  • Show 'continue with Google' or 'continue with Apple' next to the password form, so users who never set a password are not stuck on a generic error.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: SessionBird, Workforce, Spotless Laundry.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.