首页> 实战笔录 >PHP开发笔记 >PHP PHP
php计算密码强度 ,php自定义函数计算密码强度
作者:小萝卜 2019-03-25 【 PHP 自定义函数 】 浏览 2102
简介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)
相关文章
- php获取域名或主机地址、网页地址、网址参数
- php根据一个日期相对于当前时间,获得多久多久之前
- Namespace declaration statement has to be the very first statement or after any declare call in the
- bccomp在php中什么意思,PHP bccomp()用法及代码示例
- PHP常用缓存方式有哪些?
- PHP获取项目根目录
- php后台 ckeditor增加编辑代码功能
- php判断当前操作系统是linux系统还是windows系统
- php中__construct()和__initialize()的区别
- PHP后台将textarea 的值回车换行拆分至数组
