您可以將密碼存儲在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