Quick Password Policy Function in PHP

Just a quick password policy function in php. Didn’t want to have to dig around to figure out how to do it again, so I’m just posting it here

/* * * * * * * * * * * * * * * * * * * * * * * * *
Password Policy requires
– at least 8 characters
– at least 1 lower case
– at least 1 upper case
– at least 1 digit
* * * * * * * * * * * * * * * * * * * * * * * * * /
function pwdPolicy($pwd){
   $policy = “/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/”;
   if(preg_match($policy, $pwd, $matches)){
      return true;
   } else return false;
}

2 thoughts on “Quick Password Policy Function in PHP

  1. Good snippet. Would be a bit more useful with variables instead of static values.

    Also your double quotes are copying as italic double quotes and your comment closing tag has an extra space which is breaking it :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>