Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 29, 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):

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

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

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

Change password

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

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