I would like to allow the current user to change their password (managed via active directory).
I would like to validate and then set their password in Active Directory (currently using the SetPassword invoke method).
My problem is validating the password so that it meets the complexity requirements:
Not contain the user's account name or parts of the user's full name that exceed two consecutive characters Be at least six characters in length Contain characters from three of the following four categories: English uppercase characters (A through Z) English lowercase characters (a through z) Base 10 digits (0 through 9) Non-alphabetic characters (for example, !, $, #, %) Complexity requirements are enforced when passwords are changed or created.
I'm already using a CompareValidator
with two textboxes so I was thinking about adding a RegularExpressionValidator
(source 1, source 2) but I'm not sure how to get it to work with the whole "three of four categories" thing:
RegularExpressionValidator revComplex = new RegularExpressionValidator();
revComplex.ControlToValidate = _txtPassword1.ID;
revComplex.ErrorMessage = "Password must have at least 7 characters. Characters should be from at least three of the following four groups: uppercase letter, lowercase letter, digit, or special characters (for example, !, $, #, %).";
revComplex.ValidationExpression = @"^(?=.{7,})(?=.*[a-z])(?=.*[0-9])(?=.*[A-Z])(?!.*s).*$";
Surely someone has tried to do this before? How should I validate a user's password before sending it to Active Directory according to the local security policy?