Page updated Jan 16, 2024

Set up password change and recovery

Amplify Android v1 is now in Maintenance Mode until May 31st, 2024. This means that we will continue to include updates to ensure compatibility with backend services and security. No new features will be introduced in v1.

Please use the latest version (v2) of Amplify Library for Android to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

Amplify libraries should be used for all new cloud connected applications. If you are currently using the AWS Mobile SDK for Android, you can access the documentation here.

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", error) }
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.

Note that you must call confirmResetPassword in the same app session as you call resetPassword. If you close the app, you'll need to call resetPassword again.

1Amplify.Auth.confirmResetPassword(
2 "NewPassword123",
3 "confirmation code you received",
4 () -> Log.i("AuthQuickstart", "New password confirmed"),
5 error -> Log.e("AuthQuickstart", error.toString())
6);
1Amplify.Auth.confirmResetPassword("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("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("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 );