Swift:在Firebase上更改用户密码

时间:2019-04-10 20:38:03

标签: swift firebase firebase-authentication

我有三个UITextField,分别输入旧密码,新密码和确认密码。我获得了警报成功,但是我的用户密码未更改。有任何想法吗?谢谢。


@IBAction func buttonPressed(_ sender: UIButton) {
    if password != confirmPassword {
        createAlert(title: "Error", message: "Passwords do not match")
    } else {
        let user = Auth.auth().currentUser
        let credential: AuthCredential = EmailAuthProvider.credential(withEmail: (user?.email)!, password: oldPassword!)
        user?.reauthenticateAndRetrieveData(with: credential, completion: {(authResult, error) in
            if error != nil {
                self.createAlert(title: "Error", message: "failed")
            }else{
                Auth.auth().currentUser?.updatePassword(to: self.password!) { (error) in
                    print("Error")
                }
                self.createAlert(title: "Success", message: "Password change successful!")
            }
        })
    }
}

0 个答案:

没有答案