Reputation: 37633
MembershipService.ChangePassword
doesn't change password issue. I have no clue why...
var userUsers = from n in db.aspnet_Users where n.UserId == id select n;
string userName = userUsers.Single<aspnet_Users>().UserName;
MembershipUser user = Membership.GetUser(userName, false);
if (user != null)
{
string generatedPassword = user.ResetPassword();
if (MembershipService.ChangePassword(userName, generatedPassword, model.NewPassword))
{
// So it doesn't change the password
Upvotes: 2
Views: 478
Reputation: 6914
Check this out in the documentation:
ChangePassword returns
true
if the password was updated successfully. Otherwise, it returnsfalse
.
Before changing a password, ChangePassword
calls the provider's overridable OnValidatingPassword
method to validate the new password. It then changes the password or cancels the action based on the outcome of the call.
If the user name, password, new password, or password answer is not valid,
ChangePassword
does not throw an exception; it simply returns false.
Following a successful password change, ChangePassword
updates the user's LastPasswordChangedDate
.
This helped me once when I had the exact same problem. The password was not valid so the method never actually changed it. I changed some password configuration in the web.config
file and then it finally worked.
Check this lines of your web.config, this might be the problem:
<membership defaultProvider="Demo_MemberShipProvider">
<providers>
<add name="Demo_MemberShipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="cnn"
enablePasswordRetrieval="false"
**enablePasswordReset="true"**
**requiresQuestionAndAnswer="true"**
applicationName="/"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
**minRequiredPasswordLength="5"**
**minRequiredNonalphanumericCharacters="0"**
passwordAttemptWindow="10" passwordStrengthRegularExpression="">
</providers>
</membership>
Hope it helps!
Upvotes: 2