• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP判断密码强度的方法

php 搞代码 3年前 (2022-01-22) 16次浏览 已收录 0个评论

这篇文章主要介绍了PHP判断密码强度的方法,涉及php正则判断、ajax交互及页面元素动态操作相关实现技巧,需要的朋友可以参考下

具体如下:

一、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(<p>+本文来源gao!%daima.com搞$代*!码9网(</p><strong>搞gaodaima代码</strong>'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();        }    });}

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP判断密码强度的方法
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址