是否可以使用myUser.get("password")
在Cloud Code中检索用户密码?我甚至使用万能钥匙,我仍然无法取回它。
更新
PFCloud.callFunctionInBackground("updateUser", withParameters: ["username" : username, "newPassword" : newPasswordText.text, "currentPassword" : currentPasswordText.text, "operation" : 2]) {
(positions: AnyObject!, error: NSError!) -> Void in
if error == nil {
self.navigationController?.popToRootViewControllerAnimated(true)
}
else {
let errorAlert = UIAlertController (title: "Error", message: "Invalid current password", preferredStyle: UIAlertControllerStyle.Alert)
let actionCancel = UIAlertAction (title: "Dismiss", style: .Cancel, handler: nil)
errorAlert.addAction(actionCancel)
self.presentViewController(errorAlert, animated: true, completion: nil)
}
}
Parse.Cloud.define("updateUser", function(request, response) {
// Set up to modify user data
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("username", request.params.username);
query.first({
success: function(myUser) {
var password = myUser.get("password");
if (request.params.operation == 1) {
myUser.set("password", request.params.newPassword);
}
else if (request.params.operation == 2 && password == request.params.currentPassword) {
myUser.set("password", request.params.newPassword);
}
else {
response.error(password);
}
myUser.save(null, {
success: function(myUser) {
// The user was saved successfully.
response.success("Successfully updated user.");
},
error: function(myUser, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
response.error("Could not save changes to user.");
}
});
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
});
答案 0 :(得分:1)
密码在Parse中存储为单向散列值,无论设置了什么权限,都无法检索。它只能与另一个潜在密码的散列值进行比较,但您仍然无法恢复原始密码。
如果用户已输入其电子邮件地址,您可以请求密码重置过程。
Parse.User.requestPasswordReset("email@example.com", {
success: function() {
// Password reset request was sent successfully
},
error: function(error) {
// Show the error message somewhere
alert("Error: " + error.code + " " + error.message);
}
});