我正在尝试使用电子邮件/密码验证时获取用户的密码...
但是当我执行getAuth()/ onAuth()时..对象只是电子邮件,uid,令牌等......但不是密码。
我需要密码的原因是因为我希望能够更改用户密码。要做到这一点,您需要用户旧密码作为angularfire文档状态的语法:
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.changePassword({
email : "bobtony@firebase.com",
oldPassword : "correcthorsebatterystaple",
newPassword : "neatsupersecurenewpassword"
}, function(error) {
if (error === null) {
console.log("Password changed successfully");
} else {
console.log("Error changing password:", error);
}
});
三江源。
答案 0 :(得分:0)
您可以将密码存储在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");
});
})