^(?=.*[A-Z])(?=.*\d)(?!.*(.)\1\1)[a-zA-Z0-9@]{6,12}$
Special Characters - Not Allowed
Spaces - Not Allowed
Minimum and Maximum Length of field - 6 to 12 Characters
Met by [a-zA-Z0-9@]{6,12}
Numeric Character - At least one character
Met by positive lookahead (?=.*\d)
At least one Capital Letter
Met by positive lookahead (?=.*[A-Z])
Repetitive Characters - Allowed only two repetitive characters
I am not sure what you mean by this. The negative lookahead (?!.*(.)\1\1) makes sure that no character is allowed to appear more than two times in a row. Substring aa is okay, aaa is not.
Make it (?!.*(.+)\1\1) to reject repeated substrings of length more than one (like ababab) or add .* before \1 to reject non-continuous repeated appearances too.
refer:
http://stackoverflow.com/questions/12899876/checking-strings-for-a-strong-enough-password[
^]
OR
You can do these checks using positive look ahead assertions:
<pre lang="xml">^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$
<a href="http://www.rubular.com/r/UAwoaPM0Ji">Rubular link</a>[<a href="http://www.rubular.com/r/UAwoaPM0Ji" target="_blank" title="New Window">^</a>]
Explanation:
^ Start anchor
(?=.*[A-Z].*[A-Z]) Ensure string has two uppercase letters.
(?=.*[!@#$&*]) Ensure string has one special case letter.
(?=.*[0-9].*[0-9]) Ensure string has two digits.
(?=.*[a-z].*[a-z].*[a-z]) Ensure string has three lowercase letters.
.{8} Ensure string is of length 8.
$ End anchor.</pre>
refer:
regex-for-password-strength[
^]
OR
public static bool IsStrongPassword(string password)
{
if (password.Length < 6 || password.Length > 12)
return false;
if (!(password.All(c => char.IsLetter(c) || char.IsDigit(c))))
return false;
if (!password.Any(c => char.IsDigit(c)))
return false;
if (!password.Any(c => char.IsUpper(c)))
return false;
var repeatCount = 0;
var lastChar = '\0';
foreach(var c in password)
{
if (c == lastChar)
repeatCount++;
else
repeatCount = 0;
if (repeatCount == 2)
return false;
lastChar = c;
}
return true;
}
refer:
strong-password-regex[
^]