I have a ASP.NET page which allows an administrator to change the password for a user. Since the administrator does not know the user’s password, I am using the following:
MembershipUser member = Membership.GetUser(_usernameTextBox.Text); member.ChangePassword(member.ResetPassword(), _passNewTextBox.Text);
— as described by this SO question.
If the new password does not meet the complexity requirements which are configured in the web.config file, then the password will have been reset, but not changed to the desired one. If the new password does not meet complexity requirements, then the password should not change at all.
Is there an easy way to test the new password against the complexity requirements?
You can use the following properties to test the password against:
Note that the PasswordStrengthRegularExpression property will be an empty string if you have not configured it in the web.config file.
For info on regular expression matching, see the MSDN reference on Regex.IsMatch(String)
*Thanks to Matt for the helpful comments.