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):
1// Create this value on the class level to use as a state2bool 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}