您可以将密码存储在firebase数据库中。我不会推荐你,因为你会被攻击。但我会建议提示用户输入旧密码。并检查它是否写入。然后找到更改用户密码。正如代码所解释的那样(添加Sweet-Alert使其成为优先:)):
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.onAuth(function(authData) {
swal({
title: "Old Password!",
text: "Write Old Password",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "OldPassword..."
}, function(inputValue) {
if (inputValue === false) return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
$scope.originalPassword = inputValue
swal({
title: "New Password!",
text: "Write New Password",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "NewPassword..."
}, function(inputValue) {
if (inputValue === false) return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
$scope.NewPassword = inputValue
ref.changePassword({
email: authData.password.email,
oldPassword: $scope.originalPassword,
newPassword: $scope.NewPassword
}, function(error) {
if (error === null) {
swal("Nice!", "Password Changed Succesfully!", "success");
}
else {
sweetAlert("Oops...", "Error Changing Password" + error, "error");
}
});
});
swal("Nice!", "You wrote: " + inputValue, "success");
});
})
如果您已正确设计您的应用程序,那么知道用户密码的唯一方法就是询问他们。你有一个表格,用户可以提供旧密码和新密码吗? – tadman
任何服务都可以访问用户的实际密码是一种极其糟糕的做法。通常服务提供商会保存用户密码生成的密钥并进行保存。 因此,如上所述,您需要询问用户旧的*和*新密码以允许更改。 – idan
Firebase知道旧密码,所以你只需要询问用户并将输入传递给'changePassword'。您不需要知道旧密码,因为Firebase确实会检查自己 – mjr