Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 密码Regex-Gov-Reqs_Php_Mysql_Regex - Fatal编程技术网

Php 密码Regex-Gov-Reqs

Php 密码Regex-Gov-Reqs,php,mysql,regex,Php,Mysql,Regex,对于政府总承包商,希望根据其要求应用密码正则表达式: 至少有一个大写字母 至少有一个小写字母 至少一个数字 至少有一个特殊字符 具有以下代码: if(empty(trim($_POST["password"]))) { $passwordErr = "Please enter a password."; } elseif(trim($_POST["password"]) === $username) { $passwordErr = "Cannot be the

对于政府总承包商,希望根据其要求应用密码正则表达式:

  • 至少有一个大写字母
  • 至少有一个小写字母
  • 至少一个数字
  • 至少有一个特殊字符
  • 具有以下代码:

    if(empty(trim($_POST["password"]))) {
        $passwordErr = "Please enter a password.";
        } elseif(trim($_POST["password"]) === $username) {
            $passwordErr = "Cannot be the same as your username";
        } elseif(trim_check($_POST["password"]) == TRUE) {
            $passwordErr = "Please do not use a space in your password.";
        } elseif(!preg_match('/^(?=.*\d)(?=.*[\x21-\x7E])(?=.*[a-z])(?=.*[A-Z])[0-9A-Za-z\x21-\x7E]{6,50}$/',($_POST['password']))) {
            $passwordErr = "Must be six to fifty characters in length and at least one of each: <ul><li><strong>Uppercase</strong></li><li><strong>Lowercase</strong></li><li><strong>Number</strong></li><li><strong>Special Character</strong></li></ul>";
        } else {
            $password = trim($_POST['password']);
        }
    
    我想问两件事:

  • 在表达式的两个部分中都使用php正则表达式for ascii适当地定义了
    \x21-\x7E
    (有关我所指的两个部分的含义,请参见#2)
  • 表达式
    [0-9A-Za-z\x21-\x7E]
    的这一部分做了什么,这一部分
    (?=.*\d)(?=.[\x21-\x7E])(?=.[a-z])(?=.[a-z])
    还没有做什么
  • 它看起来很好用,但我不知道我是否遗漏了什么。据我所知,它至少必须包含: 1大写字母 -1小写字母 -1号 -1个特殊字符(空格除外),以及
    -它必须是一个字母、数字和特殊字符(但我觉得这是多余的)

    这是您当前的正则表达式,为便于阅读,它分为多行:

    ^
        (?=.*\d)                     \
        (?=.*[\x21-\x7E])             \
        (?=.*[a-z])                   /  assert some conditions
        (?=.*[A-Z])                  /
        [0-9A-Za-z\x21-\x7E]{6,50}   --  match here
    $
    
    前四个肯定的lookahead断言数字、特殊字符、小写和大写字母在模式中出现一次或多次。但问题是,lookaheads断言,但实际上并不匹配或消费任何东西。因此,正则表达式的最后一部分是这样做的:

    [0-9A-Za-z\x21-\x7E]{6,50}
    

    请注意,上述内容也仅限于上述类型中的字符,并且只允许使用6到50个字符。

    Gotcha、assert和match。谢谢看起来语法是正确的,我相信我已经包含了所有必要的ascii字符。谢谢你的时间!
    [0-9A-Za-z\x21-\x7E]{6,50}