Evaluting the method signature, it is required to know old password while changing it.
membershipUser.ChangePassword(userWrapper.OldPassword, userWrapper.Password)
Is there any way to change password without knowing old one.
Evaluting the method signature, it is required to know old password while changing it.
membershipUser.ChangePassword(userWrapper.OldPassword, userWrapper.Password)
Is there any way to change password without knowing old one.
You need to reset the user's password before changing it, and pass in the generated password to
ChangePassword
.or inline:
Please note, all these mentioned solutions will only work if the
RequiresQuestionAndAnswer
property is set to false in Membership system configuration. IfRequiresQuestionAndAnswer
is true then the ResetPassword method needs to be passed the security answer, otherwise it will throw an exception.In case you need
RequiresQuestionAndAnswer
set to true, you can use this workaroundThis code mentioned on posts above is working:
But you have to set requiresQuestionAndAnswer="false" in web.config in membership provider tag. If it is true, resetpassword method generate an error "Value can not be null". In this case you must supply question answer as parameter to ResetPassword.
The other answers here are correct, but can leave the password in an unknown state.
ChangePassword
will throw exceptions if the password doesn't meet the requirements laid out in Web.Config (minimum length, etc.). But it only fails afterResetPassword
has been called, so the password will not be known to the original user or to the person who's tried to change it. Check for complexity requirements before changing the password to avoid this:@Rob Church is right:
However, instead of his solution to do the validation by hand, I would try to change the password using the ResetPassword from token method and catch and show the error: