Change Membership Password with Custom Password Generator
If you find that the Membership.ResetPassword() function generates too crazy a password, or you just want complete control over password generation, you may find it difficult to change the password.
The issue is that you need the OLD password to change to the NEW password. If you are storing your passwords in hashed format, you will never be able to retrieve the old password. This slightly inefficient workaround allows you to get around this problem while still using native methods.
- Reset Password and store temporarily
- Use temporary password to change to new password
//Reset Password
MembershipUser user = Membership.GetUser(login);
if (user != null)
{
//generate a friendly password
newPassword = Util.Password.GeneratePassword(6);
//reset password and remember it
string oldPassword = user.ResetPassword();
user.ChangePassword(oldPassword, newPassword);
}