本文实例讲述了PHP判断密码强度的方法。分享给大家供大家参考,具体如下:

一、php页面

$score = 0;
if(!empty($_GET['value'])){ //接收的值
    $str = $_GET['value'];
} else{
    $str = '';
}
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 ++;
}
echo $score;
exit;

二、html页面

<table cellspacing="0" cellpadding="0">
<tr>
<td>输入密码:</td>
<td colspan="4"><input type="password" value="" name="newpwd" onblur="getPassword();" />
</tr>
<tr>
<td>密码强度:</td>
<td id="idSM1" align="middle" width="20%"><span style="height:0px; line-height:0px;">&nbsp;</span><span id="idSMT1" style="DISPLAY: none">弱</span></td>
<td id="idSM2" style="BORDER-LEFT: #fff 1px solid" align="middle" width="20%"><span style="height:0px; line-height:0px;">&nbsp;</span><span id="idSMT0" style="DISPLAY:inline; FONT-WEIGHT: normal; COLOR: #666">无</span><span id="idSMT2" style="DISPLAY: none">中等</span></td>
<td id="idSM3" style="BORDER-LEFT: #fff 1px solid" align="middle" width="20%"><span style="height:0px; line-height:0px;">&nbsp;</span><span id="idSMT3" style="DISPLAY: none">强</span></td>
<td id="idSM4" style="BORDER-LEFT: #fff 1px solid" align="middle" width="20%"> <span style="height:0px; line-height:0px;">&nbsp;</span><span id="idSMT4" style="DISPLAY: none">极好</span></td>
</tr>
</table>

三、js

<script>
function getPassword(){
    var value = $("input[name='newpwd']").attr('value');
    $.get('index.php"htmlcode">
<style>
.pwdChkCon0 {BORDER-RIGHT: #bebebe 1px solid;BORDER-BOTTOM: #bebebe 1px solid;BACKGROUND-COLOR: #ebebeb;TEXT-ALIGN: center;}
.pwdChkCon1 {BORDER-RIGHT: #bb2b2b 1px solid;BORDER-BOTTOM: #bb2b2b 1px solid;BACKGROUND-COLOR: #ff4545;TEXT-ALIGN: center;}
.pwdChkCon2 {BORDER-RIGHT: #e9ae10 1px solid;BORDER-BOTTOM: #e9ae10 1px solid;BACKGROUND-COLOR: #ffd35e;TEXT-ALIGN: center;}
.pwdChkCon3 {BORDER-RIGHT: #267a12 1px solid;BORDER-BOTTOM: #267a12 1px solid;BACKGROUND-COLOR: #3abb1c;TEXT-ALIGN: center;}
.pwdChkCon4 {BORDER-RIGHT: #267a12 1px solid;BORDER-BOTTOM: #267a12 1px solid;BACKGROUND-COLOR: #3abb1c;TEXT-ALIGN: center;}
</style>

PS:这里再为大家提供几款相关在线工具供大家参考使用:

密码安全性在线检测:
http://tools.jb51.net/password/my_password_safe

在线随机数字/字符串生成工具:
http://tools.jb51.net/aideddesign/suijishu

高强度密码生成器:
http://tools.jb51.net/password/CreateStrongPassword

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php加密方法总结》、《PHP编码与转码操作技巧汇总》、《PHP数学运算技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。

更新日志