2017-09-16 84 views
1

我有一个场景,需要在用户执行不可逆转的任务之前,根据用户的Firebase密码检查输入的密码。这与创建帐户或登录不同。您如何检查Firebase密码?它看起来不像firebase.auth().currentUser中的password财产。Firebase - 检查密码

更新: 用户必须验证他们的密码,删除按钮将运行一个函数来检查它。如果它与Firebase密码相符,则“删除”按钮将成功触发漂亮模式弹出。

Password Verification

+2

这听起来像你正在寻找[重新认证用户的凭证](https://firebase.google.com/docs/auth/web/manage-users#re-authenticate_a_user)。 –

回答

0

我建议你来存储用户密码的地方,如果你需要对证在一些点。

而不是将它存储在您的数据库内(这将不安全)我会亲自将它存储在用户的设备上使用UserDefaults,以便您可以轻松地访问它,只要您需要执行您的明智任务。

更新:

另一种可能性是使用reauthenticateWithCredential方法。如果方法返回成功,那么执行你的敏感任务。如果失败,请让用户输入正确的密码。

按照您的要求,这是你将如何使用自己的电子邮件&密码重新认证用户:

// First you get your current user using Auth : 

let currentUser = Auth.auth()?.currentUser 

// Then you build up your credential using the current user's current email and password : 

let credential = EmailAuthProvider.credential(withEmail: email, password: password)  

// use the reauthenticate method using the credential : 
currentUser?.reauthenticate(with: credential, completion: { (error) in 

    guard error == nil else { 
     return 
    } 

    // If there is no error, you're good to go 

    // ...Do something interesting here 

}) 

您可以找到火力地堡文档这里里面的一些更多的解释:https://firebase.google.com/docs/auth/ios/manage-users

+0

您能否提供一个'reauthenticateWithCredential'的例子。它需要传递一个'凭证'参数,我不知道如何使用。 – FiringBlanks

+0

当然,我会更新我的答案! – Alex