Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

RegEx Password Validation

Posted on 2014-04-11
10
Medium Priority
?
338 Views
Last Modified: 2014-04-14
I am looking for help building a regular expression for testing password complexity. The password requirements are:
 - one upper case
 - one lower case
 - one special character or number
 - at least 8 characters
0
Comment
Question by:evilmonkey2148
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39994939
What text editor, programming language, or other miscellaneous utility are you using for password validation?
0
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 39994941
(?=.*[A-Z])(?=.*[a-z])(?=.*\W).{8}
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39994966
Since \W means spaces too, I would use
(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9~!@#$%^&*]).{8,}

HTH,
Dan
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Expert Comment

by:Terry Woods
ID: 39997842
Without start and end of string placeholders, this validation may be vulnerable to failure. Details given here: http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_28411422.html#a39997831
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39997881
Terry,

I initially thought that too, but on further examination it shouldn't. Because the requirement only says, "at least 8 characters," the pattern holds. If it instead said, "between 8 and 15 characters," for example, then further restriction would be needed.
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 39997936
Ah, yes, good point! :-)
0
 

Author Comment

by:evilmonkey2148
ID: 39998986
problem with this expression:
(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9~!@#$%^&*]).{8,}

is that i need to accept any special character on the keyboard.
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39999027
Considering you use a non-Unicode variant, \W means "anything that is not a letter A to Z, a to z, a number 0 to 9 or an underscore _".

This makes _ to not be allowed as a special character, while it will accept space, tab, carriage returns, bell, etc.  

It's better, IMO to specify exactly what is a "special character". \W is faster to write/read, but that's where its merits stop.

If you want to "accept any special character on the keyboard", you need to list them.
0
 

Author Comment

by:evilmonkey2148
ID: 39999053
(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9!@#\$%\^&\*\(\)_\+-=\[\]{}\\\|;':",\./<>\?).{8,}

So that should work?
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39999069
Yup.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question