首页> 实战笔录 >PHP开发笔记 >PHP PHP
php计算密码强度 ,php自定义函数计算密码强度
作者:小萝卜 2019-03-25 【 PHP 自定义函数 】 浏览 2114
简介php计算密码强度 ,php自定义函数计算密码强度
代码如下:
/**
*计算密码强度
*@str 未加密前的密码字符串
**/
function pwdstrong($str){
$score = 0;
if(preg_match("/[0-9]+/",$str))
{
$score ++;
}
if(preg_match("/[0-9]{3,}/",$str))
{
$score ++;
}
if(preg_match("/[a-z]+/",$str))
{
$score ++;
}
if(preg_match("/[a-z]{3,}/",$str))
{
$score ++;
}
if(preg_match("/[A-Z]+/",$str))
{
$score ++;
}
if(preg_match("/[A-Z]{3,}/",$str))
{
$score ++;
}
if(preg_match("/[_|\-|+|=|*|!|@|#|$|%|^|&|(|)]+/",$str))
{
$score += 2;
}
if(preg_match("/[_|\-|+|=|*|!|@|#|$|%|^|&|(|)]{3,}/",$str))
{
$score ++ ;
}
if(strlen($str) >= 10)
{
$score ++;
}
/*
if($score<5){
return 1; //低
}elseif($score < 8){
return 2; //中
}else{
return 3; //高
}
*/
return $score;
}
很赞哦! (0)
