Password Pattern

Hi,

I need a pattern for password validation.

  1. At least 10 characters long.

  2. Include at least one digit.

  3. Include at least one special characters.




$pattern = '/^(?=.*\d(?=.*\d))(?=.*[[\W]])(?=.*[a-zA-Z](?=.*[a-zA-Z])).{5,}$/'; 



Whats change needed in this $pattern?

Thanks.

I’d split it up into separate patterns if possible. It’s much easier to set a pattern for each rule than to try to define the whole thing in one pattern.

Assuming you’re using this for model rules, you could use something like the following:




array('password', 'length', 'min'=>10),

array('password', 'match', 'pattern'=>'/\d/', 'message'=>'Password must contain at least one numeric digit.'),

array('password', 'match', 'pattern'=>'/\W/', 'message'=>'Password must contain at least one special character.'),



+1 on Keith’s solution. It’s much easier to maintain and a lot friendlier towards users.