ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsStrongPassword

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

Source

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();

Author: Arjan Keene

Submitted on: 24 feb. 2008

Language: C#

Type: System.String

Views: 6908