shubster
shubster

Reputation: 825

How to make set up condition specific password in php?

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?

Upvotes: 0

Views: 782

Answers (2)

halocursed
halocursed

Reputation: 2495

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;
            }
        }

Upvotes: 0

acrosman
acrosman

Reputation: 12900

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

Upvotes: 2

Related Questions