【问题标题】:How to know when a user has changed the password in firebaseAuthentication?如何知道用户何时更改了 firebaseAuthentication 中的密码?
【发布时间】:2018-03-05 19:25:20
【问题描述】:

目前我正在使用两个数据库来管理用户,我想做的是在用户未登录时更新 firebaseAuth 密码(通过发送 passwordResetEmail)。

然后当用户更改密码(在firebase中)并再次登录时,如果FirebaseLogin成功,我将获取密码并在另一个数据库中重置密码。

所以,我需要知道用户何时更改了 firebase 中的密码

firebaseAuth 有一种方法可以向用户发送密码重置电子邮件,我需要一种方法来知道用户何时更改了密码,我从 firebaseAuth 中找到了两种方法:

confirmPasswordReset();
checkActionCode();

我认为使用这两种方法可以识别密码重置操作,但我不知道如何使用这些方法。

另一种方法是将密码直接保存在 Firebase 数据库中,使用 addValueEventListener 或类似的东西,但我更愿意避免将密码保存在 Firebase 数据库中。

感谢您的回答。

【问题讨论】:

  • 我已经看过了,谢谢,它会很有用,但现在的问题是:我怎样才能得到那个值?,每个请求都会改变。
  • 之后你会在数据库中保存新密码吗?
  • 是的,我会,但它不会在 firebaseDatabase 中,我可以将它保存在那里(在 firebaseDB 中),但它会在平面文本中,我不希望这样做。跨度>
  • 这个答案对你有帮助吗?

标签: android firebase firebase-realtime-database firebase-authentication


【解决方案1】:

执行此操作的最佳方法可能是创建自定义重置密码电子邮件处理程序。您可以自己处理重置(并同时在两个地方重置),而不是在您的应用程序中验证密码是否已重置。您可以阅读有关实现此in the auth guide 的信息。

您提到的confirmPasswordReset()checkActionCode() 方法都应该在自定义电子邮件处理程序中使用。

您绝对不想在任何地方以纯文本形式保存用户密码。如果您必须将它们保存在第二个位置,请始终确保使用唯一的盐对其进行加密。如果您想在第二个系统上验证您的 Firebase 用户的身份,您可以使用的其他方法是:re-use their Firebase auth tokens,使用REST api to verify their password,或导出您的用户using the cli 并使用Firebase's Scrypt library 自己验证他们

【讨论】:

  • 谢谢你的回答,我会尝试使用REST api,我觉得很有趣
【解决方案2】:

为了能够使用这个方法:

confirmPasswordReset();

您需要用户输入的操作码和新密码。

完成密码重置过程,给出确认码和新密码。

更多信息在这里:https://firebase.google.com/docs/reference/js/firebase.auth.Auth#confirmPasswordReset

所以首先你需要获取actioncode:

var actionCode = getParameterByName('oobCode');

那么你需要验证操作码并从用户那里获取一个新密码并将其传递给confirmPasswordReset:

auth.verifyPasswordResetCode(actionCode).then(function(email) {
var accountEmail = email;
 auth.confirmPassordReset(actionCode, newPassword).then(function(resp) {
 // Password reset has been confirmed and new password updated.

  }).catch(function(error) {
   //error
});
}).catch(function(error) {
   //error
});

更多信息在这里:

https://firebase.google.com/docs/auth/custom-email-handler

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多