1、长度大于8,且小于20
2、不能包含连续3位及以上相同字母或数字
3、数字、小写字母、大写字母、特殊字符,至少包含三种
$password=132;
//正则验证 密码必须包含数字、字母以及特殊字符,长度8-20位
if (!preg_match("/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,20}$/",password)) {
echo(500,'密码必须包含数字、字母以及特殊字符,长度8-20位');
}
//键盘连续字符活数字
$str_continuities = array(
"1234567890 0987654321", //数字倒序
"qwertyuiop asdfghjkl zxcvbnm QWERTYUIOP ASDFGHJKL ZXCVBNM", //主键盘顺序
"poiuytrewq lkjhgfdsa mnbvcxz POIUYTREWQ LKJHGFDSA MNBVCXZ", //主键盘逆序
"qaz wsx edc rfv tgb yhn ujm QAZ WSX EDC RFV TGB YHN UJM",//主键盘正向斜
"zaq xsw cde vfr bgt nhy mju ZAQ XSW CDE VFR BGT NHY MJU",//主键盘正向斜逆序
"esz rdx tfc ygv uhb ijn okm OKM IJN UHB YGV TFC RDX ESZ",//主键盘反向斜
"zse xdr cft vgy bhu nji mko MKO NJI BHU VGY CFT XDR ZSE",//主键盘反向斜逆序
"147 369 258 852 963 741" //小键盘
//特殊字符不计算在内 否则无休止
);
//$last_char = "";
$list_char_3 = "";//连续三个字符
$chars =preg_split('/(?<!^)(?!$)/u', $input_data['password'] ); //也行是中文标点
foreach ($chars as $char) {
$list_char_3 .= $char;
// $last_char = $char;
//判断三连
if (strlen($list_char_3) >= 3) {
$list_char_3 = substr($list_char_3, strlen($list_char_3) - 3, 3);
foreach ($str_continuities as $str_continuity) {
if (strpos($str_continuity, $list_char_3) !== false) {
return '密码不能包括连续的3个字符键盘键位';
}
}
}
}