Rahul
Rahul

Reputation: 5636

ResetPassword method in ASP.NET 4.0

The ResetPassword method is able to reset the old password, but user is unable to login with the new password generated by ResetPassword method. Code:

String user =(((TextBox)PasswordRecovery2.Controls[0].FindControl("UserName")).Text).ToString();
String newPassword = clsStatic.RandomString(10, false);
MembershipUser username = Membership.GetUser(user);
String resetPassword = username.ResetPassword();
username.ChangePassword(resetPassword, newPassword);

Upvotes: 1

Views: 610

Answers (2)

codeandcloud
codeandcloud

Reputation: 55278

Your new random password generation should be ideally one of these

// this will automatically take care of all password criteria
string newPassword = Membership.GeneratePassword(10, 0);

Or

//for generating alpha numeric password only
string newPwd = Guid.NewGuid().ToString().Substring(0, 11).Replace("-", "");

Your code is fine otherwise.

Upvotes: 0

Jeroen
Jeroen

Reputation: 4023

Does ChangePassword return true or false?

I bet your random function returns a password that doesn't meet the criteria specified in your web.config membership section.

Since ResetPassword already gives you a new valid password why do you have to generate another one?

Upvotes: 1

Related Questions