IsStrongPassword

public static bool IsStrongPassword(this string s)
{
    bool isStrong = Regex.IsMatch(s, @"[\d]");
    if (isStrong) isStrong = Regex.IsMatch(s, @"[a-z]");
    if (isStrong) isStrong = Regex.IsMatch(s, @"[A-Z]");
    if (isStrong) isStrong = Regex.IsMatch(s, @"[\s~!@#\$%\^&\*\(\)\{\}\|\[\]\\:;'?,.`+=<>\/]");
    if (isStrong) isStrong = s.Length > 7;
    return isStrong;
}
Example:
//returns false
string s = "test1234";
bool b = s.IsStrongPassword();
//returns true
string s = "tesT12#4";
bool b = s.IsStrongPassword();

Description

Validates whether a string is compliant with a strong password policy.

Details

Double click on the code to select all.

 

;