I am trying to get the password of the user when i do Email/Password Authentication...
But when i do getAuth()/onAuth().. The object is just the email,uid,token,etc... but not a password.
The reason i need the password is because i want to be able to change the users password. And to do that you need the users old password as the syntax of the angularfire docs state:
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);
}
});
Thankyou.
You can store the password in the database of firebase. Which i wont recommend since you will be vurnable to attacks. But what i would reccomend is prompting the user for the old password. And check if it is write. Then Procced to changing the users password. As explained by Code(Added Sweet-Alert to make it preeety :)) :
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");
});
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.