开发者

How to make set up condition specific password in php?

开发者 https://www.devze.com 2022-12-08 18:56 出处:网络
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 l

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?


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


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

精彩评论

暂无评论...
验证码 换一张
取 消