这篇文章主要介绍了PHP判断密码强度的方法,涉及php正则判断、ajax交互及页面元素动态操作相关实现技巧,需要的朋友可以参考下
本文实例讲述了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"></tr><tr> <td>密码强度:</td><td id="idSM1" align="middle" width="20%"><span style="height:0px;line-height:0px"> </span><span id="idSMT1">弱</span></td><td id="idSM2" align="middle" width="20%"><span style="height:0px;line-height:0px"> </span><span id="idSMT0">无</span><span id="idSMT2">中等</span></td><td id="idSM3" align="middle" width="20%"><span style="height:0px;line-height:0px"> </span><span id="idSMT3">强</span></td><td id="idSM4" align="middle" width="20%"> <span style="height:0px;line-height:0px"> </span><span id="idSMT4">极好</span></td></tr></table>
三、js
function getPassword(){ var value = $("input[name='newpwd']").attr('value'); $.get('index.php?r=account/testpwd',{value:value},function(data){ if(data>=1 && data=4 && data=7 && data=9 && data<=10){ //极好 $('#idSM1').attr('class','pwdChkCon4'); $('#idSM2').attr('class','pwdChkCon4'); $('#idSM3').attr('class','pwdChkCon4'); $('#idSM4').attr('class','pwdChkCon4'); $('#idSMT0').hide(); $('#idSMT1').hide(); $('#idSMT2').hide(); $('#idSMT3').hide(); $('#idSMT4').show(); } }); }
四、css
.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;}
PS:这里再为大家提供几款相关在线工具供大家参考使用:
密码安全性在线检测:
http://tools.gaodaima.com/password/my_password_safe
在线随机数字/字符串生成工具:
http://tools.gaodaima.com/aideddesign/suijishu
高强度密码生成器:
http://tools.gaodaima.com/password/CreateStrongPassword
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php加密方法总结》、《PHP编码与转码操作技巧汇总》、《PHP数学运算技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
- PHP生
来源gao!%daima.com搞$代*!码网
成随机用户名和密码的实现代码
- php编写批量生成不重复的卡号密码代码
- php中生成随机密码的自定义函数代码
- php生成随机密码自定义函数代码(简单快速)
- PHP生成随机密码方法汇总
- php生成随机密码的三种方法小结
- php密码生成类实例
- 纯php生成随机密码
- php实现随机生成易于记忆的密码
- PHP中快速生成随机密码的几种方式
- php用户密码加密算法分析【Discuz加密算法】
以上就是PHP判断密码强度的方法详解的详细内容,更多请关注gaodaima搞代码网其它相关文章!