tags:

views:

39

answers:

2

I am learning php on my own. I am creating a new user register page using php/mysql. I want to make sure that the password entered by user in condition specific, that is, must contain one upper case letter, one number and one special character. Any suggestions?

+2  A: 

Use a regular expression to test the password against.

One (of many) ways to do this:

function check_password($text)
{
    $regex = "#.*^(?=.{8,20})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$#"
    if (preg_match($regex, $text)) {
     return TRUE;
    } 
    else {
     return FALSE;
    }
}

Also see: http://www.cafewebmaster.com/check-password-strength-safety-php-and-regex

acrosman
A: 

Try this & look up Regular Expression

function check_password($password){
      if (preg_match('/^[A-Z]+$/', $password)) {
           if (preg_match('/^[0-9]+$/', $password)) {
              if (preg_match('/^[*\+?{}.]+$/', $password)) {
                   return true;
               }
           }
      }else{
                        return false;
            }
     }
halocursed