2016-07-16 27 views

Trả lời

11

Bạn sẽ có thể đạt được nó bằng cách sử dụng reauthenticate trước khi thay đổi mật khẩu.

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

Chỉ cần thêm thông tin, here bạn có thể tìm thấy làm thế nào để thiết lập các đối tượng ủy nhiệm đối với bất cứ nhà cung cấp bạn đang sử dụng.

+1

Nó làm việc. Tôi đánh dấu nó là câu trả lời. Cảm ơn. –

+1

@AmadeuAndrade Nice! Vui mừng u đã làm nó! – adolfosrs

0

Đối 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) 
     } 
    }) 
} 

Tài liệu căn cứ hỏa lực có thể được tìm thấy here

Các vấn đề liên quan