强制执行密码要求 [英] Enforcing Password Requirements

查看:103
本文介绍了强制执行密码要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to check if the user has successfully met the following requirements:

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

我该怎么做?

我正在使用以下PHP脚本:

I am using the PHP script below:

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

推荐答案

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

You can do that with a regex:

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

这篇关于强制执行密码要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆