Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change password using Firebase in Flutter

I want to change current user password using Firebase in Flutter. Can any one help me on how to implement change password method?

like image 264
shuzuka Avatar asked Sep 12 '18 10:09

shuzuka


4 Answers

I know this is a late post, but now it's possible to change the password of the logged-in user. Make sure to notify the user to log in again since this is a sensitive operation.

void _changePassword(String password) async{
   //Create an instance of the current user. 
    FirebaseUser user = await FirebaseAuth.instance.currentUser();
   
    //Pass in the password to updatePassword.
    user.updatePassword(password).then((_){
      print("Successfully changed password");
    }).catchError((error){
      print("Password can't be changed" + error.toString());
      //This might happen, when the wrong password is in, the user isn't found, or if the user hasn't logged in recently.
    });
  }
like image 63
Abel Tilahun Avatar answered Oct 19 '22 16:10

Abel Tilahun


If you are here for the solution in 2021 and getting reauthenticate error ->

void _changePassword(String currentPassword, String newPassword) async {
final user = await FirebaseAuth.instance.currentUser;
final cred = EmailAuthProvider.credential(
    email: user.email, password: currentPassword);

user.reauthenticateWithCredential(cred).then((value) {
  user.updatePassword(newPassword).then((_) {
    //Success, do something
  }).catchError((error) {
    //Error, show something
  });
}).catchError((err) {
 
});}
like image 40
Deepanshu Chowdhary Avatar answered Oct 19 '22 16:10

Deepanshu Chowdhary


This should work according to the latest version of firebase:

final FirebaseAuth firebaseAuth = FirebaseAuth.instance;  
User currentUser = firebaseAuth.currentUser; 
currentUser.updatePassword("newpassword").then((){
  // Password has been updated.
}).catchError((err){
  // An error has occured.
})
like image 2
Peter Wauyo Avatar answered Oct 19 '22 16:10

Peter Wauyo


This is currently not supported.

When this pull request is merged https://github.com/flutter/plugins/pull/678 the Flutter firebase_auth package will support that.

like image 1
Günter Zöchbauer Avatar answered Oct 19 '22 16:10

Günter Zöchbauer