Home >php教程 >php手册 >php判断密码强度

php判断密码强度

WBOY
WBOYOriginal
2016-06-13 10:19:431082browse

一、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页面

输入密码:

密码强度:        

三、js

<script></script>

function getPassword(){

var value = $("input[name='newpwd']").attr('value');

$.get('index.php?r=account/testpwd',{value:value},function(data){

if(data>=1 && data

$('#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

$('#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

$('#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

$('#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;}

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn