php - 强制密码要求

标签 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
   }
}

最佳答案

您可以使用正则表达式来做到这一点:

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

关于php - 强制密码要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6182846/

相关文章:

php - htmlspecialchars 是否足以防止对用单引号括起来的变量进行 SQL 注入(inject)?

wcf - 此 BasicHttpBinding 的 CustomBinding?

git - 如何修复 .git 暴露的 firebase 漏洞

ruby-on-rails - 载波上传缓存

ruby-on-rails - 需要旧密码才能创建新密码

php - 获取并推送新表中的数据

PHP session_set_cookie_params 中断 php session_start() 函数和 $_SESSION 变量

php - 不能使用 mysql_real_escape_string

php - sha1(密码)加密

java - 如何在 Axis2 WebService 中通过用户名和密码进行身份验证?