Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Password Regex optimization

by bellaire (Hermit)
on Nov 18, 2009 at 19:21 UTC ( [id://807995]=note: print w/replies, xml ) Need Help??


in reply to Password Regex extended

As far as my limited skills can determine, you have basically two options:
  • Make your regex include all possible 3-out-of-4 permutations and separate them with "or" using |
  • Split your matches out into separate regexes, and count how many of them match.
Neither is particularly brief, but I think the latter is more concise and readable. Here's my example of that solution:
if (3 <= scalar grep { $str =~ /$_/ } ( # Match at least 3 of: qr/^.*(?=.{10,})(?=.*\d).*$/, qr/^.*(?=.{10,})(?=.*[a-z]).*$/, qr/^.*(?=.{10,})(?=.*[A-Z]).*$/, qr/^.*(?=.{10,})(?=.*[@#$%^&+=]).*$/ ) ) { # Do something. }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://807995]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-19 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found