Cognito "Incorrect Username or Password" When the Password Is Right: FORCE_CHANGE_PASSWORD, NEW_PASSWORD_REQUIRED, SECRET_HASH, Disabled Auth Flows, Aliases and Lockouts, Fixed
Amazon Cognito can return NotAuthorizedException: Incorrect username or password even when the password your user remembers is correct. The fastest fix is to inspect the user's status, the app client's enabled authentication flows, the client-secret requirement, and the exact user pool receiving the request. An administrator-created user might still need to complete NEW_PASSWORD_REQUIRED, while another application might send an email alias to a client configured for a different sign-in flow. The surprising part is that Cognito deliberately returns the same generic authentication error for some nonexistent users and incorrect passwords to prevent account enumeration. Repeatedly resetting the password can therefore leave the actual problem untouched.
Jake owns a small phone-repair shop. His website allows customers to book repairs and lets his employees sign in to a private dashboard. An employee receives a temporary password after Jake creates the account in Amazon Cognito, but the login page repeatedly displays the same unhelpful message: incorrect username or password.
Jake copies the temporary password directly from the invitation, checks the employee's email address, and tries again. The authentication request appears to fail, although the user definitely exists in the correct customer directory. The login problem has interrupted a real business task because the employee cannot open the afternoon repair schedule.
The problem is not necessarily the characters in the password. An administrator-created user may be required to change a temporary password before Cognito issues normal authentication tokens. If the application fails to handle that challenge, the user sees a login failure despite submitting valid temporary credentials.
Diagnose the Cognito login failure without blindly resetting passwords
When your Cognito login fails, distinguish an actual service exception from an error message generated by your application. Many front ends replace several different authentication responses with one friendly error string. A required password-change challenge can consequently look identical to an incorrect-password exception if the application handles neither case separately.
Inspect the error name and message returned by the Cognito SDK. If the request succeeds but includes ChallengeName instead of AuthenticationResult, it is not an ordinary invalid-password response. Cognito may be requesting a new password, multi-factor authentication, or another configured challenge before issuing tokens.
Your first diagnostic questions should be which user pool receives the request, which app client is used, and whether the user exists and is enabled. Next, check the account status and the client's permitted authentication flow. Finally, inspect the supplied sign-in identifier and client-secret handling.
| Symptom | Likely cause | Next action |
|---|---|---|
| Admin-created user cannot finish login | FORCE_CHANGE_PASSWORD | Handle new-password challenge |
| User-password flow rejected | Flow disabled for app client | Inspect ExplicitAuthFlows |
| Unable to verify secret hash | Missing or incorrect SECRET_HASH | Calculate HMAC-SHA256 correctly |
| Email login fails but username works | Alias or sign-in setting mismatch | Inspect pool sign-in identifiers |
| User not confirmed | UNCONFIRMED | Complete confirmation |
| Password reset required | RESET_REQUIRED | Complete password-reset flow |
| Password attempts exceeded | Temporary lockout | Stop retries and allow lockout to expire |
| Works in hosted UI, not SDK | Different client or flow | Compare client IDs and requests |
Your correct password is only one prerequisite for successful authentication. Cognito also evaluates the user profile, account state, requested flow, app client, and applicable security requirements. Changing the password cannot correct a disabled authentication flow or an application targeting the wrong user pool.
Jake: "The employee copied the password straight from the email. Why does Cognito say it is wrong?"
Ethan: "The password might be right for the first step. Your application still has to handle the next challenge instead of treating anything without tokens as a failed login."
Read the user's real status in the Cognito console
When one account fails and other accounts work, examine the affected user before modifying the whole app client. Each user profile in your pool includes a status showing which authentication steps are available or required. This often gives you a more direct diagnosis than interpreting a generic login-screen error.
- Open the Amazon Cognito console and choose User pools.
- Select the user pool associated with your application.
- Choose Users.
- Find the user and open the profile.
- Read the account status and check whether the user is enabled.
- Review relevant attributes, including username, email, and verification status.
If you see CONFIRMED, the user profile has been confirmed. It does not guarantee that the supplied password is correct or that the app client's flow is permitted. A confirmed account can still fail authentication because of a wrong password, disabled user, or incorrect client configuration.
The status FORCE_CHANGE_PASSWORD means the user has a temporary password and must establish a permanent password. The status RESET_REQUIRED means the account requires a password-reset flow before ordinary sign-in. The status UNCONFIRMED means the account still needs confirmation.
| User status | Meaning | Typical action |
|---|---|---|
CONFIRMED | Account confirmed | Inspect flow and credentials |
FORCE_CHANGE_PASSWORD | Temporary password | Complete NEW_PASSWORD_REQUIRED |
UNCONFIRMED | Registration not confirmed | Complete confirmation |
RESET_REQUIRED | Password reset needed | Complete reset with code |
EXTERNAL_PROVIDER | Federated user profile | Inspect external sign-in path |
Also check whether your user is enabled. The enabled/disabled setting is separate from UserStatus. A user may be confirmed but disabled by an administrator, so inspecting only the status field gives an incomplete picture.
For a CLI diagnostic, use admin-get-user. This operation requires IAM authorization and is intended for administrative or trusted server-side access. Run it from your terminal or a trusted server, not from a public browser holding privileged AWS credentials.
aws cognito-idp admin-get-user \
--user-pool-id us-east-1_ExamplePool \
--username jake@example.com \
--region us-east-1
Fix FORCE_CHANGE_PASSWORD for administrator-created users
If the affected user was created with AdminCreateUser, inspect whether the account remains in FORCE_CHANGE_PASSWORD. If you created the user as an administrator with a temporary password, that user normally has to change it at first sign-in. The original temporary password is intended to begin an authentication process, not necessarily to produce tokens immediately.
When Cognito accepts valid temporary credentials, its response can include ChallengeName: NEW_PASSWORD_REQUIRED and a session string. Your application must present a form for the new password. It then sends the new password and the session value to the appropriate challenge-response API.
If your code assumes every successful InitiateAuth response contains AuthenticationResult, it can misclassify the challenge response as a login error. That mistake commonly affects applications that support ordinary self-registered users but never implemented the first-login journey for administrator-created users.
You have two possible fixes. The preferred user-driven approach is to complete the required password challenge. Alternatively, a trusted administrator can set a permanent password with AdminSetUserPassword, where this is consistent with your organization's password-handling policy.
aws cognito-idp admin-set-user-password \
--user-pool-id us-east-1_ExamplePool \
--username employee@example.com \
--password "$NEW_PERMANENT_PASSWORD" \
--permanent \
--region us-east-1
The command above changes a real user's password and permits immediate sign-in with the newly set permanent password. Use it only with authorization from the account owner or the appropriate administrative policy. Keep plaintext passwords out of your shared shell history, tickets, logs and source code.
Jake: "I created the employee's account myself. Does that mean the password in the invitation is temporary?"
Ethan: "Usually, yes. The employee must set a permanent password before getting a normal session. Your login form needs to handle that challenge."
Complete NEW_PASSWORD_REQUIRED with the correct Cognito API
When your application receives NEW_PASSWORD_REQUIRED, keep the authentication session from the initial response. The session connects the subsequent challenge answer to the original sign-in attempt. Starting an unrelated authentication request does not replace the required challenge response.
For user-initiated authentication, use InitiateAuth followed by RespondToAuthChallenge. For IAM-authorized administrative authentication, use AdminInitiateAuth followed by AdminRespondToAuthChallenge. The two families serve different authorization models and should be selected deliberately.
Your challenge response supplies USERNAME and NEW_PASSWORD. An app client with a secret also requires SECRET_HASH. The response must include the session returned by the authentication request, and any required user attributes identified by the challenge must be supplied.
aws cognito-idp initiate-auth \
--client-id "$CLIENT_ID" \
--auth-flow USER_PASSWORD_AUTH \
--auth-parameters \
USERNAME=employee@example.com,PASSWORD="$TEMP_PASSWORD" \
--region us-east-1
The example assumes a client without a secret and with ALLOW_USER_PASSWORD_AUTH enabled. When the response contains NEW_PASSWORD_REQUIRED, save its session string securely for the next authentication step. Treat the session value as sensitive authentication material.
aws cognito-idp respond-to-auth-challenge \
--client-id "$CLIENT_ID" \
--challenge-name NEW_PASSWORD_REQUIRED \
--session "$AUTH_SESSION" \
--challenge-responses \
USERNAME=employee@example.com,NEW_PASSWORD="$NEW_PASSWORD" \
--region us-east-1
A successful challenge response may return authentication tokens or another required challenge. For example, your pool might require multi-factor authentication before finishing sign-in. Handle the actual response type rather than assuming that changing the password always completes every authentication requirement.
Your API challenge session has an expiration period set on the app client. The default is three minutes for user pools API authentication sessions. If the session expires, begin authentication again rather than trying to reuse an expired challenge session.
Match InitiateAuth and AdminInitiateAuth to enabled authentication flows
If your password works through one Cognito integration but fails through another, inspect the authentication flow each integration requests. Your app client must explicitly permit each authentication flow you use. Passing a correct username and password cannot override a client configuration that does not authorize the requested flow.
The USER_PASSWORD_AUTH flow is initiated with InitiateAuth and requires ALLOW_USER_PASSWORD_AUTH. The administrative password flow ADMIN_USER_PASSWORD_AUTH uses AdminInitiateAuth and requires ALLOW_ADMIN_USER_PASSWORD_AUTH. Administrative API calls also require appropriate AWS IAM credentials.
Cognito also supports Secure Remote Password authentication, commonly abbreviated SRP. In SRP authentication, the client proves knowledge of the password without sending the plaintext password as the authentication parameter. Applications using SRP should rely on a properly implemented SRP client rather than substituting a different flow name without modifying their request construction.
| Flow | API | Client setting |
|---|---|---|
USER_PASSWORD_AUTH | InitiateAuth | ALLOW_USER_PASSWORD_AUTH |
ADMIN_USER_PASSWORD_AUTH | AdminInitiateAuth | ALLOW_ADMIN_USER_PASSWORD_AUTH |
USER_SRP_AUTH | InitiateAuth | ALLOW_USER_SRP_AUTH |
USER_AUTH | InitiateAuth or AdminInitiateAuth | ALLOW_USER_AUTH |
CUSTOM_AUTH | InitiateAuth | ALLOW_CUSTOM_AUTH |
Choice-based USER_AUTH is available with the appropriate user pool feature tier and app client settings. It can support password, SRP, passkey, and supported one-time-password methods. Your app must follow the returned challenges instead of assuming the first response always contains tokens.
Inspect the client using the Cognito console under Applications → App clients, or use describe-user-pool-client. An incompatible flow often produces an explicit flow-not-enabled error rather than the generic incorrect-password response. Preserve that original exception instead of replacing it with a generic message in the front end.
aws cognito-idp describe-user-pool-client \
--user-pool-id "$POOL_ID" \
--client-id "$CLIENT_ID" \
--region us-east-1 \
--query 'UserPoolClient.{
ClientName:ClientName,
ExplicitAuthFlows:ExplicitAuthFlows,
PreventUserExistenceErrors:PreventUserExistenceErrors
}'
Jake: "Can I just enable every authentication option and stop worrying about it?"
Ethan: "Enable the flows your application actually implements. A client that calls USER_PASSWORD_AUTH needs that flow permitted, but an admin flow also needs trusted AWS credentials."
Compute SECRET_HASH correctly for app clients with a secret
If the app client has a secret, certain Cognito authentication operations require a calculated client-secret hash. This is separate from your user's password. A correct password does not replace the requirement to prove that a trusted application knows the client secret.
The SECRET_HASH parameter is a Base64-encoded HMAC-SHA256 value. Its key is the app client's secret, and its message is the username value concatenated with the app client ID. The order of concatenation matters, and so does the username value you pass for that operation.
The calculation is:
SECRET_HASH =
Base64(
HMAC_SHA256(
key = CLIENT_SECRET,
message = USERNAME + CLIENT_ID
)
)
Use the hash in the AuthParameters of InitiateAuth or AdminInitiateAuth. For challenge-response operations, put the hash in ChallengeResponses. Other APIs, such as SignUp or ForgotPassword, use the separately named SecretHash request parameter.
Python example
import base64
import hashlib
import hmac
import os
username = os.environ["COGNITO_USERNAME"]
client_id = os.environ["COGNITO_CLIENT_ID"]
client_secret = os.environ["COGNITO_CLIENT_SECRET"]
message = (username + client_id).encode("utf-8")
secret_hash = base64.b64encode(
hmac.new(
client_secret.encode("utf-8"),
message,
hashlib.sha256
).digest()
).decode("utf-8")
print(secret_hash)
The code reads environment variables, so your client secret stays out of your source code. The output is the hash value, not the secret. In production, calculate it on a trusted server and never expose the client secret in a public browser or mobile application.
Node.js example
import { createHmac } from "node:crypto";
function calculateSecretHash(username, clientId, clientSecret) {
return createHmac("sha256", clientSecret)
.update(username + clientId, "utf8")
.digest("base64");
}
const secretHash = calculateSecretHash(
process.env.COGNITO_USERNAME,
process.env.COGNITO_CLIENT_ID,
process.env.COGNITO_CLIENT_SECRET
);
// Send secretHash in AuthParameters.SECRET_HASH.
If you receive Unable to verify secret hash for client, inspect the client ID, client secret, input username, and hash encoding. A hash generated for another app client will not work. A server-side application that changes usernames between the initial challenge and the response can also calculate the wrong hash.
For certain refresh-token authentication paths, the username input for secret hashing depends on the pool's sign-in attributes. When username is not a sign-in attribute, the user's sub claim is used for the relevant refresh-token hash calculation. When username is a sign-in attribute, the username claim is used instead.
⚠️ Keep the client secret server-side
A Cognito app client secret is not appropriate for JavaScript shipped to browsers or secrets embedded in publicly distributed mobile applications. Use a public app client without a secret for those environments, or keep secret-enabled authentication behind a trusted backend.
Fix username, email alias, and sub mismatches
If login succeeds with one identifier but not another, inspect the pool's sign-in configuration. Cognito supports usernames, email addresses, phone numbers, and preferred usernames under particular sign-in settings. A valid email attribute does not automatically mean every user pool accepts that email address as a sign-in alias.
You also need to keep a username and the sub attribute apart. The sub is the stable unique identifier for the user within the pool. It is suitable for identifying a user in application records, while the accepted login identifier depends on the pool's sign-in configuration.
An email alias can be accepted during sign-in when the pool is configured to allow that alias and its verification requirements are satisfied. In contrast, when the pool uses email as a username attribute, Cognito has a different username model. The two configurations are not interchangeable.
For a practical diagnosis, compare the user's Username from admin-get-user with the application's submitted USERNAME value. Inspect the user pool's AliasAttributes and UsernameAttributes. Confirm whether the application is using an accepted sign-in identifier for that specific pool.
aws cognito-idp describe-user-pool \
--user-pool-id "$POOL_ID" \
--region us-east-1 \
--query 'UserPool.{
Id:Id,
AliasAttributes:AliasAttributes,
UsernameAttributes:UsernameAttributes,
UsernameConfiguration:UsernameConfiguration
}'
If the sign-in options are incorrect for your application, plan a migration rather than expecting to edit a permanent pool-level choice. Cognito does not permit changing the fundamental username and alias selection of an existing user pool. Creating a new pool requires deliberate migration of users and application integrations.
Jake: "The employee's email is right there in the profile. Why can't it always be used as the username?"
Ethan: "The email attribute and the login rules are separate things. The pool must permit email as a sign-in identifier, and its alias requirements still apply."
Check Cognito username case sensitivity before changing credentials
If login succeeds for Jake@example.com but fails for jake@example.com, examine the user pool's case sensitivity. Some Cognito pools treat differently capitalized identifiers as distinct, while others consider them equivalent. The setting belongs to the pool rather than the individual app client.
If you created your pool in the AWS Management Console, it is case insensitive by default. When creating a pool through the API or CLI, omitting CaseSensitive can instead produce a case-sensitive pool. Older pools can also have case-sensitive behavior, so assumptions based on a newly created console pool may not describe your production environment.
A case-insensitive pool treats differently capitalized usernames and configured aliases as equivalent for sign-in. A case-sensitive pool requires the appropriate capitalization. This can make a copied email address fail even though the underlying password is correct for the differently capitalized username.
Inspect UsernameConfiguration.CaseSensitive with describe-user-pool. Then compare the identifier submitted by the application with the stored user identity. A capitalization mismatch is no reason to change your user's password.
The case sensitivity setting cannot be changed in place after creating a pool. A migration to a new pool must account for existing usernames that differ only by capitalization, because those profiles can conflict in a case-insensitive destination. Use the stable sub attribute as an application identity key rather than assuming email capitalization always identifies a unique account.
Resolve disabled, unconfirmed, and reset-required accounts
If a user exists and the password appears valid, confirm that the account is enabled. Cognito can disable a user independently of the confirmation status. A disabled profile cannot simply be made usable by changing its app client's authentication flow.
If you are an authorized administrator, you can restore a disabled account with AdminEnableUser. Before doing this, establish why the account was disabled. If it was suspended for a security or business reason, restoring it without authorization is the wrong fix.
aws cognito-idp admin-enable-user \
--user-pool-id "$POOL_ID" \
--username employee@example.com \
--region us-east-1
An UNCONFIRMED user needs to complete the appropriate registration confirmation procedure. For a normal self-registration flow, that commonly involves a confirmation code and the ConfirmSignUp API. An authorized administrator can also use AdminConfirmSignUp where appropriate.
Users in RESET_REQUIRED need a password reset rather than an ordinary login retry. The self-service recovery path commonly uses ForgotPassword followed by ConfirmForgotPassword. An administrator can begin a reset through AdminResetUserPassword, which places the user into a reset-required state and starts the applicable reset process.
Pay attention to the actual exception your code receives. UserNotConfirmedException describes a different condition from PasswordResetRequiredException. Presenting both as incorrect passwords forces users to repeat an action that will not resolve the account's real state.
Recover an account with an expired temporary password
When an administrator-created user attempts the first login long after receiving the invitation, the temporary password may have expired. The password might still be copied accurately from the original email, but it is no longer an acceptable temporary credential. This is a different problem from entering the wrong password characters.
Cognito's TemporaryPasswordValidityDays password-policy setting controls the temporary-password validity interval. The default is seven days, and the configurable limit is up to 365 days. If the temporary password expires before the user completes first sign-in, the account requires administrative recovery.
The preferred recovery option is to issue a fresh temporary password through the supported administrative user-creation resend procedure. An AdminCreateUser request with MessageAction=RESEND can generate and send a new temporary password, renewing the invitation process. The existing user does not need to be deleted merely because the original temporary password expired.
Alternatively, an administrator with suitable authority can set a new temporary password with AdminSetUserPassword without the permanent flag. That returns the user to the required password-change process. Use the permanent option only when the intended workflow allows the administrator to set a permanent credential directly.
aws cognito-idp admin-create-user \
--user-pool-id "$POOL_ID" \
--username employee@example.com \
--message-action RESEND \
--region us-east-1
An expired temporary password is not the same as an expired confirmation code or an expired challenge session. Those are different credentials with different lifetimes and recovery APIs. Use the account status and the actual exception to determine which one failed.
Worked example: Fix a login that fails only for admin-created users
Consider Jake's employee dashboard with 20 existing self-registered users and three newly created employee accounts. The 20 regular users sign in normally. The three administrator-created accounts cannot finish login, even when their invitation passwords are copied exactly.
The first diagnostic step is to compare the account statuses. Suppose all 20 existing users show CONFIRMED, while the three new users show FORCE_CHANGE_PASSWORD. This is strong evidence that the application is missing its first-sign-in password-change handling.
The next diagnostic step is to inspect the actual API response for one authorized test user. Suppose InitiateAuth accepts the temporary credentials and returns ChallengeName=NEW_PASSWORD_REQUIRED with a session string. The response explains why normal tokens were not issued: the user must first establish a permanent password.
| Group | Users | Account state | Expected authentication |
|---|---|---|---|
| Existing users | 20 | CONFIRMED | Normal sign-in, subject to configured challenges |
| New employees | 3 | FORCE_CHANGE_PASSWORD | NEW_PASSWORD_REQUIRED |
The application is then changed to handle the response's challenge name. Instead of displaying a generic credential error when AuthenticationResult is absent, it opens a new-password form and retains the challenge session. The employee enters a permanent password that satisfies the pool's password policy.
Next, the application submits RespondToAuthChallenge with NEW_PASSWORD, USERNAME, and the session. If the app client has a secret, it also supplies SECRET_HASH. The new-password response must then be handled for tokens or additional challenges.
This example changes the correct component of the system: the login workflow. Lowering the password policy, recreating all users, or disabling Cognito's account-confirmation protections would not solve the missing challenge handler. Once the application's first-login journey is supported, the three new accounts have a valid path to normal authentication.
Jake: "So the 20 existing accounts were fine because they had already set permanent passwords?"
Ethan: "Exactly. Your new employees needed one extra screen. The solution was to handle Cognito's challenge, not to weaken the passwords."
Explain why the same password works in the hosted UI but fails in code
If Cognito's hosted login succeeds while your custom code fails, compare the complete authentication paths instead of only the entered password. Managed login can handle supported user-facing authentication steps within Cognito's hosted experience. Your custom SDK integration must implement the corresponding challenge sequence itself.
Your managed login and your custom application may also use different app clients. Each app client can have different authentication flows, client-secret settings, token settings, and managed login configuration. A password accepted through one client does not establish that another client is correctly configured.
Start by finding the app client ID used in the hosted login authorization request. Compare it with the client ID passed by your SDK. Then inspect the flow used by your code and confirm it is enabled on that app client.
For temporary-password users, managed login can present the required password-change interaction. If your code expects only tokens from its first authentication response, the same user's journey fails in the custom application. This is especially common when development testing used existing confirmed accounts rather than newly administrator-created accounts.
Another possibility is that the hosted interface supports a configured sign-in method that your SDK request does not implement. For example, managed login and a custom application may choose different password, SRP, or choice-based authentication paths. Match the intended authentication design before modifying user credentials.
Jake: "If Cognito's own sign-in page works, doesn't that prove my SDK request should work too?"
Ethan: "It proves the hosted path works. Your code can use a different client, a different flow, and a different challenge handler."
Verify the correct user pool, client ID, AWS account, and Region
When credentials work in development but not production, inspect the environment's Cognito resource identifiers. Your user pools are Region-specific resources, and users in separate pools are separate identities. An email address appearing in two pools does not mean the accounts share the same password.
Your application needs the correct app client ID and regional Cognito endpoint. Administrative operations additionally require the correct user pool ID and IAM credentials. Environment variables copied from another deployment can cause an authentication request to target the wrong resources even when the login form itself looks correct.
Inspect the configured Region and the app client's actual parent user pool. For an administrative diagnostic, use the pool ID and Region together. Compare the values against the Cognito console for the intended environment.
aws sts get-caller-identity
aws cognito-idp describe-user-pool-client \
--user-pool-id "$POOL_ID" \
--client-id "$CLIENT_ID" \
--region us-east-1
The first command identifies the AWS identity used by the CLI. The second identifies the client configuration in the specified user pool. These are useful diagnostics when your console session and terminal use different AWS accounts or profiles.
Use separate, clearly named configuration values for development, staging, and production. If a production environment variable is missing, your app should fail loudly instead of quietly falling back to a development pool. A misrouted login should be logged as a configuration defect without recording the user's plaintext password.
Recover from Password attempts exceeded without extending the lockout
If repeated login attempts produce Password attempts exceeded, Cognito has temporarily locked password authentication for that account. This is not evidence that a previously correct password was changed. It is a protective response to repeated failed attempts.
After five failed password sign-in attempts, Cognito begins with a one-second lockout. Each additional failed attempt after a lockout expires doubles the subsequent lockout duration, up to approximately 15 minutes. Attempts during an active lockout produce the lockout error and do not increase the duration.
Your user can recover by letting the current lockout expire and then signing in successfully. Alternatively, 15 consecutive minutes without initiating sign-in attempts resets the failed-attempt count. Your app should stop sending automated retries while the user is locked out.
| Cumulative failed attempts | Illustrative lockout |
|---|---|
| 5 | 1 second |
| 6 | 2 seconds |
| 7 | 4 seconds |
| 8 | 8 seconds |
| Additional attempts | Exponential backoff up to approximately 15 minutes |
The most practical fix is to stop repeated attempts and correct the underlying authentication problem before trying again. A front end that automatically retries a failed password request can make the experience worse by driving the account toward longer lockouts. Your code should treat a password error differently from a passing network failure.
There is no reason to replace the user account merely to clear this temporary lockout. Follow the normal recovery interval and investigate whether incorrect credentials, mismatched client configuration, or automated retries caused the failures. For users who genuinely no longer know the password, use the supported password-recovery process.
Understand why Cognito deliberately hides some login failure details
If Cognito returns the same error for a nonexistent user and a wrong password, the behavior can be intentional. The app client setting PreventUserExistenceErrors controls whether supported authentication paths reveal that an account does not exist. Suppressing that distinction helps prevent user enumeration.
User enumeration occurs when someone uses different login responses to determine which usernames or email addresses belong to real accounts. A public login page that clearly distinguishes nonexistent users can provide information to an attacker. Generic responses reduce that disclosure.
When PreventUserExistenceErrors=ENABLED, supported username-password authentication flows return a generic incorrect-credentials error for nonexistent users. When the setting is LEGACY, those flows can instead return UserNotFoundException. The exact behavior depends on the authentication flow, including special handling for choice-based and SRP authentication.
The Cognito console selects prevention of user existence errors by default for newly created app clients. App clients created through the API can have the legacy setting if it is not explicitly configured. Compare the configuration rather than assuming every client in your account behaves identically.
For security, keep the public response reasonably generic while recording appropriate nonsecret diagnostic information in trusted server-side systems. Administrative operations can help determine account state when the person investigating has authorization. Your public login form can stay vague; your support team can look up the account state with admin tools instead.
Distinguish related Cognito errors instead of treating everything as a bad password
When you investigate a failed sign-in, keep the actual exception type. Cognito returns different exceptions for different failures, even though your application may choose to show a simplified public message. Those differences guide the recovery flow.
UserNotConfirmedException means the account needs confirmation. PasswordResetRequiredException means the user must complete the password-reset process. NotAuthorizedException is broader and must be interpreted with its message, request context, and the client configuration.
The message Password attempts exceeded indicates a temporary lockout from repeated failed password attempts. Unable to verify secret hash for client points to the client-secret hash rather than directly to the user's password. A flow-not-enabled error points to app client configuration.
| Error or response | Meaning | Correct direction |
|---|---|---|
Incorrect username or password | Generic authentication failure | Check pool, user identity, and credentials |
NEW_PASSWORD_REQUIRED | First-login challenge | Submit new password with session |
UserNotConfirmedException | Account not confirmed | Complete confirmation |
PasswordResetRequiredException | Reset needed | Complete password reset |
Password attempts exceeded | Temporary lockout | Stop retrying and allow recovery |
Unable to verify secret hash | Client-secret proof incorrect | Correct hash inputs |
ExpiredCodeException | Expired confirmation or reset code | Request a new code as appropriate |
One important distinction is that an expired temporary password and an expired verification code are not the same thing. Their recovery methods differ. Treating them as equivalent can result in resending the wrong credential and leaving the account unusable.
When building the login interface, use challenge responses to display the next appropriate screen and exceptions to select safe error handling. Keep detailed diagnostic records on the trusted backend where possible. Keep your app secrets, raw passwords and authentication session values out of your logs.
Troubleshoot Cognito login when the obvious fixes still fail
If the account is confirmed, enabled, and using the expected pool and client, examine the full authentication exchange. Your application might be receiving a challenge but never showing it. It might also compute SECRET_HASH using an alias that differs from the required value for the particular operation.
Next, inspect the application's request parameters and compare them with the allowed authentication flows. A working managed login session is a useful comparison, but its client ID and authentication method may differ from the custom SDK integration. Matching only the displayed username and password is insufficient.
If a problem appears only after refresh-token rotation or token renewal, inspect the refresh method rather than treating it as an initial password failure. Refresh-token operations have their own client configuration and username-selection considerations. The login password may not be involved in that request at all.
If the problem affects migrated or federated users, examine the account's identity source and migration workflow. A profile in EXTERNAL_PROVIDER status is not necessarily a native password-authenticated user. Likewise, user migration triggers introduce application-specific behavior that must be evaluated separately from ordinary local-user login.
If the problem continues, gather the exception code, AWS Region, pool ID, client ID, authentication flow, sanitized request shape, relevant account status, and timestamp. An AWS Support case can use this information to investigate a Cognito service issue, while application developers can use it to identify incorrect client configuration or challenge handling. Keep passwords, client secrets, tokens, and session credentials out of the support ticket.
Frequently asked questions about Cognito Incorrect username or password
Why does Cognito say Incorrect username or password when the password is correct?
The request may be targeting the wrong user pool, using an incorrect sign-in identifier, or receiving a deliberately generic authentication failure. The app client might also be configured differently from the login experience that succeeds. Check the original API error and user status before resetting credentials.
What does FORCE_CHANGE_PASSWORD mean in Cognito?
It means the user has a temporary password and must set a permanent password before completing ordinary authentication. A valid temporary-password login returns the NEW_PASSWORD_REQUIRED challenge. Your application must complete that challenge or use an authorized administrative password-setting process.
How do I complete NEW_PASSWORD_REQUIRED in Cognito?
Begin with the supported authentication flow and retain the session from the challenge response. Submit NEW_PASSWORD and USERNAME using RespondToAuthChallenge or AdminRespondToAuthChallenge. Include SECRET_HASH when required by the app client.
Why does Cognito login work in the hosted UI but not in my code?
The hosted login and custom code may use different app clients or authentication flows. Managed login can handle supported challenges that your SDK application must implement itself. Compare client IDs, permitted flows, and the full challenge responses.
How do I compute Cognito SECRET_HASH?
Calculate Base64 of HMAC-SHA256 using the app client secret as the key and the username concatenated with the client ID as the message. Supply the result in the operation's required SECRET_HASH or SecretHash field. Use the correct username identity for the operation.
What is the difference between InitiateAuth and AdminInitiateAuth?
InitiateAuth supports user-initiated authentication with an app client. AdminInitiateAuth supports IAM-authorized administrative authentication and requires appropriate AWS credentials. They use different flow names and permissions.
How can I check Cognito user status in the console?
Open Cognito User pools, select the pool, choose Users, and open the user profile. Review its status and whether it is enabled. The CLI equivalent is aws cognito-idp admin-get-user.
How do I unlock Cognito after Password attempts exceeded?
Stop repeated sign-in attempts and let the temporary lockout expire. A successful login after the lockout, or 15 consecutive minutes without sign-in attempts, resets the failure count. Correct any automated retry loop before attempting authentication again.
How long does Cognito lock a user after incorrect passwords?
After five failed password attempts, Cognito begins with a one-second lockout and doubles the duration for additional failures. The lockout increases up to approximately 15 minutes. Attempts during an active lockout do not further increase the duration.
Can Cognito email aliases cause an incorrect password error?
Yes, when an application submits an identifier that is not accepted under the pool's sign-in configuration. Email aliases and email-as-username configurations have different requirements. Inspect the pool's alias and username attributes before changing the password.
Is Cognito username case sensitive?
It depends on the pool's case sensitivity setting. Console-created pools are case insensitive by default, but pools created through API operations can be case sensitive. Inspect UsernameConfiguration.CaseSensitive to determine the behavior.
How do I fix UserNotConfirmedException in Cognito?
Complete the appropriate user confirmation process. Self-registered users typically confirm with a code, while authorized administrators can confirm users through supported administrative APIs. A new password alone does not necessarily confirm the account.
What happens when a Cognito temporary password expires?
The user cannot complete initial sign-in using the expired temporary credential. An administrator can issue a new temporary password, including through the AdminCreateUser resend process. The configured temporary-password validity defaults to seven days.
Can I fix a disabled Cognito user by resetting the password?
A password reset does not replace the account's enabled setting. An authorized administrator must inspect why the user is disabled and, where appropriate, restore access using AdminEnableUser. The user may still need additional authentication steps afterward.
Why does Cognito return the same error for nonexistent users and wrong passwords?
With PreventUserExistenceErrors enabled, supported authentication flows use generic responses to reduce user enumeration. This prevents a login endpoint from easily revealing which accounts exist. Trusted administrative diagnostics can establish account status without disclosing that information publicly.
What should I check when Cognito authentication still fails after resetting the password?
Inspect the correct pool, Region, client ID, permitted flow, username or alias, user status, and secret-hash handling. Check whether the authentication response contains a challenge rather than tokens. Preserve the original exception and investigate configuration before performing further password resets.
For readers preparing for an AWS certification
We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.
Exams that test this topic: Developer – Associate (DVA-C03 from December 1, 2026) • Security – Specialty (SCS-C03) • Solutions Architect – Associate (SAA-C03).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. A web app needs sign-up and sign-in, including Google and Apple accounts. Which service fits?
An Amazon Cognito user pool, with Google and Apple added as federated identity providers.
2. Signed-in users need temporary AWS credentials to upload to their own S3 prefix. What do you add?
A Cognito identity pool that exchanges the user pool token for IAM role credentials, with a policy scoped by the identity ID.
3. A REST API must accept only requests from signed-in user pool users, with no custom code. What do you use?
A Cognito user pool authorizer on the API Gateway REST API.
4. Where should an app client secret live?
Only on a trusted server. Browser and mobile apps use an app client without a secret.
5. All users must use a second factor at sign-in. What do you configure?
Set MFA to required on the user pool, with TOTP, SMS or email codes.
6. A login page must not reveal whether an email address has an account. Which app client setting helps?
PreventUserExistenceErrors set to ENABLED, which returns generic errors for unknown users.
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
For Jake's phone-repair shop, the lasting fix is making the login application respond correctly to the user's actual account state. An invited employee needs a supported first-password-change experience, while a disabled or unconfirmed user needs a different recovery process. If you encounter the same generic Cognito error, inspect the user, the client, and the authentication flow before asking anyone to reset a password again. I hope your next login investigation leads to the actual failed step instead of another round of guessing at credentials.
📌 If you keep one line from this page
In Cognito, a correct password is only one part of successful sign-in; the user's status, app client, and authentication flow must agree too.
Revision note. Written October 19, 2026. "The key is in the details," as the saying goes; with Cognito, the details are the user status and the app client.