Click here to Skip to main content
15,885,141 members
Articles / General Programming / Regular Expressions
Tip/Trick

ASP.NET Password Strength Regular Expression

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
5 Jan 2011CPOL 37.7K   7   5
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.



(?=^.{12,25}$)(?=(?:.*?\d){2})(?=.*[a-z])(?=(?:.*?[A-Z]){2})(?=(?:.*?[!@#$%*()_+^&}{:;?.]){1})(?!.*\s)[0-9a-zA-Z!@#$%*()_+^&]*$


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 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I have over 10 years of experience working with Microsoft technologies. I have earned my Microsoft Certified Technology Specialist (MCTS) certification. I'm a highly motivated self-starter with an aptitude for learning new skills quickly.

Comments and Discussions

 
SuggestionUpdate - due to no XML encoding and missing chars Pin
Hunter Beanland7-Jan-14 14:00
Hunter Beanland7-Jan-14 14:00 
GeneralRe: Update - due to no XML encoding and missing chars Pin
Bryian Tan24-Feb-14 17:26
professionalBryian Tan24-Feb-14 17:26 
GeneralReason for my vote of 5 Good work! Pin
Abdul Quader Mamun5-Jan-11 17:53
Abdul Quader Mamun5-Jan-11 17:53 
Generalgood work! 5/5 Pin
Abdul Quader Mamun5-Jan-11 17:53
Abdul Quader Mamun5-Jan-11 17:53 
GeneralReason for my vote of 5 nice one Pin
vikas amin5-Jan-11 9:24
vikas amin5-Jan-11 9:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.