Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regx For Password Complexity

Status
Not open for further replies.

biglurch

Programmer
Aug 25, 2005
35
US
Im trying to write a password complexity regular expression for php this is what i got so far i want it to require 6-12 chars 1 cap letter 1 number and allow symbols and small case letters. Any suggestions please let me know.

/(^[A-Za-z0-9]{1,}$){6,12}/

Live by the code, Die by the code!!
 
i'm not sure whether it's all possible in one expression. i'd love to see a solution!

how about this?

Code:
function validPassword($pwd){
 //taken from [URL unfurl="true"]http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C4F005D3717[/URL]
   $pattern = '/^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/';
   if (strlen($pwd) < 6) return false;
   if (!preg_match($pattern, $pwd)) return false;
   return true;
}
 
biglurch.

You need to fine tune the syntax, but it can be on the same line

Code:
if ( strlen($pwd) >= 6 && strlen($pwd) <= 12 && $pwd =~ /[A-Z]/ && $pwd =~ /\d/ && $pwd !~ /[^A-Za-z0-9_]/ )

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top