您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 盘锦分类信息网,免费分类信息发布

php怎么判断密码的强度实例详解

2026/1/18 12:56:24发布26次查看
网站是一个可以帮助用户检测自己所设置的密码安全性和被破解所花费时间的检测网站,其目的是告诉用户密码不要设置成简单的123456,而是要包含数字、字母、特殊符号等,提高密码的安全能力。本篇文章主要介绍怎么使用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;"> </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;"> </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;"> </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;"> </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?r=account/testpwd',{value:value},function(data){ if(data>=1 && data<=3){ $('#idsm1').attr('class','pwdchkcon1'); //弱 $('#idsm2').attr('class','pwdchkcon0'); $('#idsm3').attr('class','pwdchkcon0'); $('#idsm4').attr('class','pwdchkcon0'); $('#idsmt1').show(); $('#idsmt0').hide(); $('#idsmt2').hide(); $('#idsmt3').hide(); $('#idsmt4').hide(); } else if(data>=4 && data<=6){ //中等 $('#idsm1').attr('class','pwdchkcon2'); $('#idsm2').attr('class','pwdchkcon2'); $('#idsm3').attr('class','pwdchkcon0'); $('#idsm4').attr('class','pwdchkcon0'); $('#idsmt0').hide(); $('#idsmt1').hide(); $('#idsmt2').show(); $('#idsmt3').hide(); $('#idsmt4').hide(); } else if(data>=7 && data<=8){ //强 $('#idsm1').attr('class','pwdchkcon3'); $('#idsm2').attr('class','pwdchkcon3'); $('#idsm3').attr('class','pwdchkcon3'); $('#idsm4').attr('class','pwdchkcon0'); $('#idsmt0').hide(); $('#idsmt1').hide(); $('#idsmt2').hide(); $('#idsmt3').show(); $('#idsmt4').hide(); } else if(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
<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>
以上就是php怎么判断密码的强度实例详解的详细内容。
盘锦分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product