执行密码要求

Gle*_*aya 13 php security passwords

我想检查用户是否已成功满足以下要求:

  • 密码至少包含8个字符
  • 由一个大写和一个小写字母组成

我该怎么做?

我正在使用下面的PHP脚本:

if ( strlen( $password ) < 8 ) {
     false
} else {
   if ( preg_match( "/[^0,9]/", $password ) ) {
     // how to check the upper case and lower case
   }
}
Run Code Online (Sandbox Code Playgroud)

Joh*_*nde 9

你可以用正则表达式做到这一点:

if (!preg_match('/^(?=[a-z])(?=[A-Z])[a-zA-Z]{8,}$/', $password))
{
    //error
}
Run Code Online (Sandbox Code Playgroud)


And*_*per 4

使用preg_match("/[A-Z]/")preg_match("/[a-z]/")