I was wondering if there's a built-in method in C# .NET framework to check if a string, representing a new user password is too simple?
For instance, stuff like "1234" or "qwerty" or "33333" is too simple.
PS. I obviously can code all this myself. I was just curious, if there's something built into the platform that can do this for me before I begin.
You can use the MembershipProvider.PasswordStrengthRegularExpression property in combination with the MinRequiredPasswordLength and MinRequiredNonAlphanumericCharacters to make sure the password meets your specific needs.
there is no built-in method in C# but you can easily setup a regular expression that checks:
At least 7 chars At least 1 uppercase char (A-Z) At least 1 number (0-9) At least one special char
public static bool IsPasswordStrong(string password)
{
return Regex.IsMatch(password, @"^.*(?=.{7,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).*$");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With