Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 569
  • Last Modified:

regular expression - password policy enforcement

Hello Experts,

I need a regular expression string that matches (1 capitol, 1 lowercase, 1 number, 1 special character)

I had this:
\A(?=[-@!$^*()~_a-zA-Z0-9]*?[A-Z])(?=[-@!$^*()~_a-zA-Z0-9]*?[a-z])(?=[-@!$^*()~_a-zA-Z0-9]*?[0-9])[-@!$^*()~_a-zA-Z0-9]{8,16}\z

which seemed to be working until I added the '#' character to the string at which point it quits. Unfortunately this problem got missed until about a week away from production so I am reaching out...

Any help appreciated!
I am using this expression with the PCRE engine.
0
glo-dba
Asked:
glo-dba
  • 4
1 Solution
 
alainbrydenCommented:
This regular expression seems to have everything you need. If you don't require at least 10 characters you can remove that first part:
http://davidhayden.com/blog/dave/archive/2004/09/25/501.aspx

^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$

    * Must be at least 10 characters
    * Must contain at least one one lower case letter, one upper case letter, one digit and one special character
    * Valid special characters (which are configurable) are -   @#$%^&+=

--
Alain
0
 
alainbrydenCommented:
Well it looks like your problem might be that in the PCRE documentation, comments are delimited by the # mark. Maybe you need to escape it by using it twice? (##)
0
 
alainbrydenCommented:
I stand corrected, apparently using \# to escape the hash character should take care of it.
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.

 
alainbrydenCommented:
Here's the man page for your reference: http://www.pcre.org/pcre.txt
The relevant section for the # problem has the header "BACKSLASH"
0
 
gremwellCommented:
By the way, you may also want to escape $ sign, otherwise Perl will expand $^ variable.
0
 
glo-dbaAuthor Commented:
Your string works fine. My string doesn't work. It may be may an inconsistency in the "regex buddy" PRCE engine.

Thank you very much!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now