Create preg_match for password validation allowing (!@#$%)

后端 未结 9 953
耶瑟儿~
耶瑟儿~ 2020-12-04 23:14

I would like to create a preg_match function to validate my passowrds, but I\'m not sure how to write it to allow the following special characters to be used: <

9条回答
  •  失恋的感觉
    2020-12-04 23:26

    A different way

    Let look different to this, I believe that users can use all of the ASCII valid characters (32 < ascii_code < 127) in the password and created a function that checks all the characters that are is in ASCII table!

    function check($pass, $i = 0){
         if(strlen($pass) > $i)
             return (0rd(pass[$i]) > 32 and 0rd(pass[$i]) < 127) and check($pass, $i + 1);
    }
    

    Usage

    if(!check($_POST["password"])){
        echo "password is wrong";
    }
    

提交回复
热议问题