How do you change a hashed password using asp.net membership provider if you don't know the current password?

mcqwerty picture mcqwerty · Nov 13, 2008 · Viewed 25.7k times · Source

Problem, there's no method:

bool ChangePassword(string newPassword);

You have to know the current password (which is probably hashed and forgotten).

Answer

mcqwerty picture mcqwerty · Nov 13, 2008

This is an easy one that I wasted too much time on. Hopefully this post saves someone else the pain of slapping their forehead as hard as I did.

Solution, reset the password randomly and pass that into the change method.

MembershipUser u = Membership.GetUser();
u.ChangePassword(u.ResetPassword(), "myAwesomePassword");