I have a password criterion as:
Minimum password length is 8 characters. Password must contain characters from at least 3 of the following 4 categories:
English upper case characters (A through Z)
English lower case characters (a through z)
Numerical digits (0 through 9)
Non alpha-numerical characters (i.e. punctuation such as @#$%^+ ( )
I am using
Regex compareRegex = new Regex(@"^(?=.*[a-z]{1})(?=.*[A-Z]{1}).{7,}$");
Regex numRegex = new Regex(@"[a-zA-Z0-9].{7,}" );
if (compareRegex.IsMatch(strPassword))
{
int count = txtLoginPassword.Text.IndexOfAny(new char[] { '/', '\\', '[', ']', ':', ';', '|', '=', ',', '+', '*', '?', '<', '>', '@', '\"', '!', '#', '$', '%', '^', '&', '(', ')', '_', '-', '~', '`', '.' });
if (count >= 0)
return true;
if (numRegex.IsMatch(strPassword))
return true;
else
return false;
}
else if (numRegex.IsMatch(strPassword))
{
bool valid = false;
int count = txtLoginPassword.Text.IndexOfAny(new char[] { '/', '\\', '[', ']', ':', ';', '|', '=', ',', '+', '*', '?', '<', '>', '@', '\"', '!', '#', '$', '%', '^', '&', '(', ')', '_', '-', '~', '`', '.' });
valid = (count >= 0);
return valid;
}
else
{
return false
}
But it is not working. Pls help