Javascript Firebase-检查密码

Javascript Firebase-检查密码,javascript,firebase,Javascript,Firebase,我有一个场景,要求在用户执行不可逆任务之前,根据用户的firebase密码检查输入的密码。这与创建帐户或登录不同。如何检查firebase密码?在firebase.auth().currentUser中似乎没有password属性 更新: 用户必须验证其密码,删除按钮将运行一个功能来检查密码。如果它与firebase密码匹配,删除按钮将成功触发一个漂亮的模式弹出 如果您需要在某个时候检查用户密码,我建议您将其存储在某个地方 我不会将其存储在数据库中(这样会不安全),而是使用UserDefault

我有一个场景,要求在用户执行不可逆任务之前,根据用户的firebase密码检查输入的密码。这与创建帐户或登录不同。如何检查firebase密码?在
firebase.auth().currentUser
中似乎没有
password
属性

更新: 用户必须验证其密码,删除按钮将运行一个功能来检查密码。如果它与firebase密码匹配,删除按钮将成功触发一个漂亮的模式弹出


如果您需要在某个时候检查用户密码,我建议您将其存储在某个地方

我不会将其存储在数据库中(这样会不安全),而是使用UserDefaults将其存储在用户的设备上,以便您可以在需要执行合理任务时轻松访问它

更新:

另一种可能是使用ReAuthenticationWithCredential方法。如果方法返回成功,则执行敏感任务。如果失败,请要求用户键入正确的密码

根据您的请求,以下是您使用用户的电子邮件和密码重新验证用户的方式:

// 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

})

您可以在Firebase文档中找到更多解释:

如果您需要在某个时候检查用户密码,我建议您将其存储在某个位置

我不会将其存储在数据库中(这样会不安全),而是使用UserDefaults将其存储在用户的设备上,以便您可以在需要执行合理任务时轻松访问它

更新:

另一种可能是使用ReAuthenticationWithCredential方法。如果方法返回成功,则执行敏感任务。如果失败,请要求用户键入正确的密码

根据您的请求,以下是您使用用户的电子邮件和密码重新验证用户的方式:

// 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

})

您可以在Firebase文档中找到更多解释:

听起来像是您在寻找。听起来像是您在寻找。您能提供一个
使用凭据重新验证的示例吗。它需要传入一个
credential
参数,我不知道如何使用该参数。请提供
reaauthenticatewithcredential
的示例。它需要传入一个
credential
参数,我不知道如何使用它。