Page updated Jan 16, 2024

Set up password change and recovery

Amplify Flutter v0 is now in Maintenance Mode until July 19th, 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 v0.

Please use the latest version (v1) of Amplify Flutter to get started.

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

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):

1// Create this value on the class level to use as a state
2bool isPasswordReset = false;
3
4...
5
6Future<void> resetPassword() async {
7 try {
8 final result = await Amplify.Auth.resetPassword(
9 username: 'myusername',
10 );
11 setState(() {
12 isPasswordReset = result.isPasswordReset;
13 });
14 } on AmplifyException catch (e) {
15 safePrint(e);
16 }
17}

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

1Future<void> confirmResetPassword() async {
2 try {
3 await Amplify.Auth.confirmResetPassword(
4 username: 'myusername',
5 newPassword: 'mynewpassword',
6 confirmationCode: '123456'
7 );
8 } on AmplifyException catch (e) {
9 print(e);
10 }
11}

Change password

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

1Future<void> updatePassword() async {
2 try {
3 await Amplify.Auth.updatePassword(
4 newPassword: 'mynewpassword',
5 oldPassword: 'myoldpassword'
6 );
7 } on AmplifyException catch (e) {
8 print(e);
9 }
10}