2016-07-16 115 views

risposta

11

È possibile raggiungerlo utilizzando reauthenticate prima di modificare la 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 
    } 
}) 

solo per aggiungere ulteriori informazioni, here si possono trovare come impostare l'oggetto credenziale per qualsiasi fornitore che si sta utilizzando.

+1

Ha funzionato. L'ho segnato come risposta. Grazie. –

+1

@AmadeuAndrade Bello! Sono contento che ce l'abbia fatta! – adolfosrs

0

per 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) 
     } 
    }) 
} 

Documentazione Firebase può essere trovato here

Problemi correlati