php判斷密碼強度

來源:互聯網
上載者:User
一、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> 

相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。