• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP判断密码强弱级别

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
1 <div class="form-group">
2     <i class="icons icon-pwd2"></i>
3     <input type="text" class="form-control" name="newpassword" placeholder="请输入新密码"  />
4 </div>
1 <div class="form-group" > 
2    <tr>
3       <td>密码强度:</td>
4        <td >弱</span></td>
5        <td >中等</span></td>
6        <td >强</span></td>
7        <td >极好</span></td>
8    </tr>
9</div>
 1 $(function(){
 2     // 判断密码强弱级别
 3     $(document).on('blur','#newpassword',function(){
 4         $('#hide').show();
 5         var value = $("input[name='newpassword']").val().trim();
 6         if(value == ''){
 7             $('#hide').hide();
 8             $('#idSMT1').hide();
 9             $('#idSMT0').hide();
10             $('#idSMT2').hide();
11             $('#idSMT3').hide();
12             $('#idSMT4').hide();
13         }
14 
15         $.post('judgepassword',{value:value},function(data){
16             if(data>=1 && data<=3){
17                 $('#idSM1').attr('class','pwdChkCon1'); //
18                 $('#idSM2').attr('class','pwdChkCon0');
19                 $('#idSM3').attr('class','pwdChkCon0');
20                 $('#idSM4').attr('class','pwdChkCon0');
21                 $('#idSMT1').show();
22                 $('#idSMT0').hide();
23                 $('#idSMT2').hide();
24                 $('#idSMT3').hide();
25                 $('#idSMT4').hide();
26             } else if(data>=4 && data<=6){ //中等
27                 $('#idSM1').attr('class','pwdChkCon2');
28                 $('#idSM2').attr('class','pwdChkCon2');
29                 $('#idSM3').attr('class','pwdChkCon0');
30                 $('#idSM4').attr('class','pwdChkCon0');
31                 $('#idSMT0').hide();
32                 $('#idSMT1').hide();
33                 $('#idSMT2').show();
34                 $('#idSMT3').hide();
35                 $('#idSMT4').hide();
36             } else if(data>=7 && data<=8){ //
37                 $('#idSM1').attr('class','pwdChkCon3');
38                 $('#idSM2').attr('class','pwdChkCon3');
39                 $('#idSM3').attr('class','pwdChkCon3');
40                 $('#idSM4').attr('class','pwdChkCon0');
41                 $('#idSMT0').hide();
42                 $('#idSMT1').hide();
43                 $('#idSMT2').hide();
44                 $('#idSMT3').show();
45                 $('#idSMT4').hide();
46             } else if(data>=9 && data<=10){ //极好
47                 $('#idSM1').attr('class','pwdChkCon4');
48                 $('#idSM2').attr('class','pwdChkCon4');
49                 $('#idSM3').attr('class','pwdChkCon4');
50                 $('#idSM4').attr('class','pwdChkCon4');
51                 $('#idSMT0').hide();
52                 $('#idSMT1').hide();
53                 $('#idSMT2').hide();
54                 $('#idSMT3').hide();
55                 $('#idSMT4').show();
56             }
57         });
58     });
59 });        

PHP代码:

 1  /**
 2      * 判断密码重点级别
 3      * @return [type] [description]
 4      */
 5     public function judgepassword()
 6     {
 7         $score = 0;
 8         if(!empty($_POST['value'])){ //接收的值
 9             $str = $_POST['value'];
10         } else{
11             $str = '';
12         }
13         if(preg_match("/[0-9]+/",$str))
14         {
15             $score ++;
16         }
17         if(preg_match("/[0-9]{3,}/",$str))
18         {
19             $score ++;
20         }
21         if(preg_match("/[a-z]+/",$str))
22         {
23             $score ++;
24         }
25         if(preg_match("/[a-z]{3,}/",$str))
26         {
27             $score ++;
28         }
29         if(preg_match("/[A-Z]+/",$str))
30         {
31             $score ++;
32         }
33         if(preg_match("/[A-Z]{3,}/",$str))
34         {
35             $score ++;
36         }
37         if(preg_match("/[_|\-|+|=|*|!|@|#|$|%|^|&|(|)]+/",$str))
38         {
39             $score += 2;
40         }
41         if(preg_match("/[_|\-|+|=|*|!|@|#|$|%|^|&|(|)]{3,}/",$str))
42         {
43             $score ++ ;
44         }
45         if(strlen($str) >= 10)
46         {
47             $score ++;
48         }
49         echo $score;
50     }

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
64bitwindowserver2008R2搭建apache+mysql+php服务器。发布时间:2022-07-10
下一篇:
php数组分页发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap