MemberhipUser.ChangePassword crashes without warning

If I call user.ChangePassword (oldpass, newpass), and the old password is incorrect or the new password does not meet the complexity requirement of the provider, the method fails without warning. is there any way to find out if there is an error and what is the error.

I can always put these checks into my code, but there must be a way to do this using the membership APIs

+1
asp.net-membership
source share
1 answer

Unfortunately not. The ChangePassword method returns only a simple bool for success / failure.

The best option for a failure is to display a general message to the user indicating all the possible reasons for the failure ... for example.

Failed to change password.
Perhaps this happened because:

  • Invalid old password
  • The new password did not meet the required complexity.
  • New passwords must be 8 characters long and contain at least 2 numeric characters. (or something else)

If you want to provide more specific information, then, as you said, you will need to perform a rule check in your own code and pass the information to the user based on this check.

+5
source share

All Articles