Page updated Jan 16, 2024

Set up password change and recovery

Reset password

In order to reset your password, use the resetPassword api - this will send a code to the user attribute configured to receive such a reset code (e.g. email or SMS):

1Amplify.Auth.resetPassword(
2 "username",
3 result -> Log.i("AuthQuickstart", result.toString()),
4 error -> Log.e("AuthQuickstart", error.toString())
5);
1Amplify.Auth.resetPassword("username",
2 { Log.i("AuthQuickstart", "Password reset OK: $it") },
3 { Log.e("AuthQuickstart", "Password reset failed", it) }
4)
1try {
2 val result = Amplify.Auth.resetPassword("username")
3 Log.i("AuthQuickstart", "Password reset OK: $result")
4} catch (error: AuthException) {
5 Log.e("AuthQuickstart", "Password reset failed", error)
6}
1RxAmplify.Auth.resetPassword("username")
2 .subscribe(
3 result -> Log.i("AuthQuickstart", result.toString()),
4 error -> Log.e("AuthQuickstart", error.toString())
5 );

To complete the password reset process, invoke the confirmResetPassword api with the code you were sent and the new password you want.

1Amplify.Auth.confirmResetPassword(
2 "Username",
3 "NewPassword123",
4 "confirmation code you received",
5 () -> Log.i("AuthQuickstart", "New password confirmed"),
6 error -> Log.e("AuthQuickstart", error.toString())
7);
1Amplify.Auth.confirmResetPassword("Username", "NewPassword123", "confirmation code",
2 { Log.i("AuthQuickstart", "New password confirmed") },
3 { Log.e("AuthQuickstart", "Failed to confirm password reset", it) }
4)
1try {
2 Amplify.Auth.confirmResetPassword("Username", "NewPassword123", "code you received")
3 Log.i("AuthQuickstart", "New password confirmed")
4} catch (error: AuthException) {
5 Log.e("AuthQuickstart", "Failed to confirm password reset", error)
6}
1RxAmplify.Auth.confirmResetPassword("Username","NewPassword123", "confirmation code")
2 .subscribe(
3 () -> Log.i("AuthQuickstart", "New password confirmed"),
4 error -> Log.e("AuthQuickstart", error.toString())
5 );

Change password

A signed in user can update their password using the updatePassword api:

1Amplify.Auth.updatePassword(
2 "existingPassword",
3 "newPassword",
4 () -> Log.i("AuthQuickstart", "Updated password successfully"),
5 error -> Log.e("AuthQuickstart", error.toString())
6);
1Amplify.Auth.updatePassword("existingPassword", "newPassword",
2 { Log.i("AuthQuickstart", "Updated password successfully") },
3 { Log.e("AuthQuickstart", "Password update failed", it) }
4)
1try {
2 Amplify.Auth.updatePassword("existingPassword", "newPassword")
3 Log.i("AuthQuickstart", "Updated password successfully")
4} catch (error: AuthException) {
5 Log.e("AuthQuickstart", "Password update failed", error)
6}
1RxAmplify.Auth.updatePassword("existingPassword", "newPassword")
2 .subscribe(
3 () -> Log.i("AuthQuickstart", "Updated password successfully"),
4 error -> Log.e("AuthQuickstart", error.toString())
5 );