Skip to content

Instantly share code, notes, and snippets.

@VesselinVassilev
Created March 6, 2019 23:18
Show Gist options
  • Select an option

  • Save VesselinVassilev/8291a8c2c0e359681da3aaad63da9c88 to your computer and use it in GitHub Desktop.

Select an option

Save VesselinVassilev/8291a8c2c0e359681da3aaad63da9c88 to your computer and use it in GitHub Desktop.
How to Change User's password without knowing the existing one
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