PHP判斷密碼強(qiáng)度的方法詳解
本文實(shí)例講述了PHP判斷密碼強(qiáng)度的方法。分享給大家供大家參考,具體如下:
一、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>密碼強(qiáng)度:</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">強(qiáng)</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){ //強(qiáng) $('#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>
PS:這里再為大家提供幾款相關(guān)在線工具供大家參考使用:
密碼安全性在線檢測(cè):
http://tools.jb51.net/password/my_password_safe
在線隨機(jī)數(shù)字/字符串生成工具:
http://tools.jb51.net/aideddesign/suijishu
高強(qiáng)度密碼生成器:
http://tools.jb51.net/password/CreateStrongPassword
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php加密方法總結(jié)》、《PHP編碼與轉(zhuǎn)碼操作技巧匯總》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》、《php正則表達(dá)式用法總結(jié)》、及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
php7連接MySQL實(shí)現(xiàn)簡(jiǎn)易查詢程序的方法
這篇文章主要給大家介紹了關(guān)于php7連接MySQL實(shí)現(xiàn)簡(jiǎn)易查詢程序的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10一個(gè)基于PDO的數(shù)據(jù)庫操作類(新) 一個(gè)PDO事務(wù)實(shí)例
原先已經(jīng)寫過一個(gè)PDO的數(shù)據(jù)庫操作類,這次只是在原先基礎(chǔ)上進(jìn)行修改。2011-07-07php實(shí)現(xiàn)兩表合并成新表并且有序排列的方法
這篇文章主要介紹了php實(shí)現(xiàn)兩表合并成新表并且有序排列的方法,涉及針對(duì)數(shù)組的遍歷與排序操作技巧,具有一定的實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12PHP基于php_imagick_st-Q8.dll實(shí)現(xiàn)JPG合成GIF圖片的方法
這篇文章主要介紹了PHP基于php_imagick_st-Q8.dll實(shí)現(xiàn)JPG合成GIF圖片的方法,需要的朋友可以參考下2014-07-07javascript+php實(shí)現(xiàn)根據(jù)用戶時(shí)區(qū)顯示當(dāng)?shù)貢r(shí)間的方法
這篇文章主要介紹了javascript+php實(shí)現(xiàn)根據(jù)用戶時(shí)區(qū)顯示當(dāng)?shù)貢r(shí)間的方法,實(shí)例分析javascript獲取客戶端時(shí)區(qū)及與服務(wù)器端php交互的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03Android App中DrawerLayout抽屜效果的菜單編寫實(shí)例
這篇文章主要介紹了Android App中DrawerLayout抽屜效果的菜單編寫實(shí)例,包括結(jié)合Toolbar實(shí)現(xiàn)復(fù)合Material Design的策劃菜單例子,需要的朋友可以參考下2016-03-03比較簡(jiǎn)單的百度網(wǎng)盤文件直鏈PHP代碼
通過正則表達(dá)式獲取百度網(wǎng)盤的文件真實(shí)地址,來實(shí)現(xiàn)直鏈的效果2013-03-03