How to check the current user password when changing the password on Firebase 3?

I want the user to insert the current password and a new one when updating the password.

I searched the Firebase documentation and did not find a way to verify the current user password.

Does anyone know if this is possible?

+7
ios swift firebase firebase-authentication
source share
2 answers

You can achieve this by re-authenticating yourself before changing the password.

let user = FIRAuth.auth()?.currentUser let credential = FIREmailPasswordAuthProvider.credentialWithEmail(email, password: currentPassword) user?.reauthenticateWithCredential(credential, completion: { (error) in if error != nil{ self.displayAlertMessage("Error reauthenticating user") }else{ //change to new password } }) 

To add more information, here , you can find a way to set up a credential object for any provider you use.

+12
source share

For Swift 4:

 typealias Completion = (Error?) -> Void func changePassword(email: String, currentPassword: String, newPassword: String, completion: @escaping Completion) { let credential = EmailAuthProvider.credential(withEmail: email, password: currentPassword) Auth.auth().currentUser?.reauthenticate(with: credential, completion: { (error) in if error == nil { currentUser.updatePassword(to: newPassword) { (errror) in completion(errror) } } else { completion(error) } }) } 

Firebase documentation can be found here.

+5
source share

All Articles