- Newest
- Most votes
- Most comments
When a user's password expires in Amazon Cognito and MFA is enabled, you may be experiencing multiple OTP (One-Time Password) messages being sent during the authentication flow. This happens because the system is sending one OTP for the password reset process and another for the MFA verification.
To reduce the number of OTPs sent when a user has an expired password, you can implement the following solutions:
-
Modify your Pre-Authentication Lambda Trigger: Instead of forcing an immediate password reset when detecting an expired password, you could set a flag in the user attributes indicating the password needs to be changed at the next successful authentication. This way, the user completes their MFA authentication first, and then is prompted to change their password afterward.
-
Use AdminResetUserPassword with care: If your lambda-expirationPasswordTimeChecker is using AdminResetUserPassword to force password resets, consider that this immediately invalidates the user's current authentication attempt and triggers a separate password reset flow, which can result in multiple OTPs.
-
Consolidate the authentication flow: Adjust your authentication flow to handle both the password reset and MFA verification in a single sequence. You can use custom authentication challenges to manage this process more efficiently.
-
Consider using TOTP (Time-based One-Time Password) MFA: If appropriate for your use case, software token MFA (TOTP) using authenticator apps doesn't require sending additional OTPs via SMS or email. Users would generate the code from their authenticator app instead.
-
Adjust the password expiration timing: You could modify your EXPIRATION_PASSWORD_MONTHS setting to create a grace period where users are warned about upcoming password expiration but can still authenticate normally for a short time.
Remember that your custom password expiration implementation using Lambda triggers gives you flexibility to control exactly when and how the password reset occurs in relation to the MFA verification, allowing you to optimize the user experience.
Sources
Cognito_MFA_Reset_or_reconfigure_for_user | AWS re:Post
Authentication with Amazon Cognito user pools - Amazon Cognito
Adding MFA to a user pool - Amazon Cognito
How can I enforce password expiration in Amazon Cognito User Pools | AWS re:Post
Relevant content
- AWS OFFICIALUpdated 3 years ago
