简体   繁体   中英

Validate user inputted password against user password saved on parse server before changing password

I am working on an application using Parse.com as backend support.I have implemented change Password using this code

if (pwdController!.text == newpwdController!.text)     {
user.password = pwdController!.text;
await user.save();  

I want the user to enter the current password before allowing them change it to a new one but when I try to get the current password from the parseuser object it returns null, all the other similar questions I've seen such as this Change Password and Forgot Password with ParseUser in Parse.com aren't validating that the user has the correct current password. How can I validate that the password entered by user is their current password before letting them change it?

You can verify that the user has entered the correct current password by calling the ParseUser.login method with the username and entered password. Then check if it returns a successful response.

ParseUser user = await ParseUser.currentUser();// this gets the current user object
var nuser = (user.username, oldpwdController!.text,     user.username);


var resp = await nuser.login();
if (resp.success) {
user.password = pwdController!.text;
await user.save();

The snippet of code above assumes that you have two textcontrollers(oldpwdController for current password, and pwdController for new password to change to).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM