Tuesday, January 4, 2011

ASP.NET Password Strength Regular Expression

ASP.NET Password Strength Regular Expression. Customize n numbers of upper case, digits,
Special characters.
Shown below is the regular expression for password strength with n number of digits,
Upper case, special characters and at least 12 characters in length.

<span style="font-size: 9pt;">(?=^.{<span class="code-digit"><span style="background-color: white; color: navy;">12</span></span>,<span class="code-digit"><span style="background-color: white; color: navy;">25</span></span>}$)(?=(?:.*?\d){<span class="code-digit"><span style="background-color: white; color: navy;">2</span></span>})(?=.*[a-z])(?=(?:.*?[A-Z]){<span class="code-digit"><span style="background-color: white; color: navy;">2</span></span>})(?=(?:.*?[!@#$%*()_
+^&}{:;?.]){<span class="code-digit"><span style="background-color: white; color: navy;">1</span></span>})(?!.*\s)[<span class="code-digit"><span style="background-color: white; color: navy;">0</span></span>-9a-zA-Z!@#$%*()_+^&]*$</span>

Explanation:

(?=^.{12,25}$) -- password length range from 12 to 25, the numbers are adjustable

(?=(?:.*?[!@#$%*()_+^&}{:;?.]){1}) -- at least 1 special characters (!@#$%*()_+^&}{:;?.}) ,
the number is adjustable

(?=(?:.*?\d){2}) -- at least 2 digits, the number is adjustable

(?=.*[a-z]) -- characters a-z

(?=(?:.*?[A-Z]){2}) -- at least 2 upper case characters, the number is adjustable






No comments :

Post a Comment