Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change OWIN Identity password with out old password by code?

I have a web application in MVC5 with OWIN Identity and i want to know if there is a posibility to change from code a user password with out knowing the old password. Because the method ChangePassword ask for userId, oldPassword and newPassword.

like image 601
Phoenix_uy Avatar asked Jan 23 '15 13:01

Phoenix_uy


People also ask

How to reset password c#?

Local users who forget their password can have a security token sent to their email account, enabling them to reset their password. The user will soon get an email with a link allowing them to reset their password. Selecting the link will take them to the Reset page.

How can I change my password in asp net?

After successful login a Change password link will be visible. Here by clicking the link a new page will appear where the user must enter the Current Password, New Password and Confirm Password and then click on the Update button to change his/her password respectively.


1 Answers

In this case you will be treating ChangePassword as Reset Password. You can achieve this by using reset password by generating token and using that token straightaway to validate it with new password.

var userId = User.Identity.GetUserId();

var token = await UserManager.GeneratePasswordResetTokenAsync(userId);

var result = await UserManager.ResetPasswordAsync(userId, token, newPassword);

Check this one for more details.

Hope this helps.

like image 188
DSR Avatar answered Sep 22 '22 13:09

DSR