Iswanto San
Iswanto San

Reputation: 18569

Validate Old Password Before Change Password

I tried to change password my account in LDAP using ActiveDirectoryMembershipProvider.ChangePassword

MembershipUser currentUser = Membership.GetUser(User.Identity.Name, userIsOnline: true);
changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);

If i enter wrong old password, the ChangePassword return false. My question is: is false result from ChangePassword method means my old password is wrong? If not, how can i detect if I enter wrong password?

Thanks!

Upvotes: 0

Views: 1609

Answers (1)

Heslacher
Heslacher

Reputation: 2167

The MembershipUser.ChangePassword() method returns true if the update was successful. It does not provide any information if the oldpassword has been wrong or not.

As this method calls the ChangePassword() method of the underlaying membership provider it could also throw an exception if the membership provider has restriction on e.g the size of the password which the new password didn`t match.

Throws ArgumentException if

Throws MembershipPasswordException if

  • newPassword does not meet the complexity requirements defined by the Active Directory server.

To check your old password you can use the MembershipProvider.ValidateUser() method.

Upvotes: 1

Related Questions