Created
March 6, 2019 23:18
-
-
Save VesselinVassilev/8291a8c2c0e359681da3aaad63da9c88 to your computer and use it in GitHub Desktop.
How to Change User's password without knowing the existing one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void ChangeUserPassword(string newPassword, Guid userId) | |
| { | |
| var uManager = UserManager.GetManager(); | |
| using (new ElevatedModeRegion(uManager)) | |
| { | |
| // first reset the user's password - that would gives us the "current" password | |
| string tempPass = uManager.ResetPassword(userId, string.Empty); | |
| // now that we have the current password, we can change it | |
| uManager.ChangePassword(userId, tempPass, newPassword); | |
| uManager.SaveChanges(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment