PHP Judgment Password strength

Source: Internet
Author: User
One, php page $score = 0; if (!empty ($_get[' value ')) { //received value $STR = $_get[' value '];} else{$str = ';} if (Preg_match ("/[0-9]+/", $str)) {$score + +;} if (Preg_match ("/[0-9]{3,}/", $str)) {$score + +;} if (pre G_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)) {$sco Re + = 2; } if (Preg_match ("/[_\-+=*!@#$%^& ()]{3,}/", $str)) {$score + +;} if (Strlen ($STR) >=) {$score + +;} echo $score; Exit Second, HTML page <table cellspacing= "0" cellpadding= "0" > <tr> <td> input password:</td> <td colspan= "4" > <input type= "Password" value= "name=" Newpwd "onblur=" GetPassword (); "/> </tr> <tr> <td> Password strength: </td> <td id= "idSM1" align= "Middle" width= "20% ><span" style=; line-height:0px; " > </span><span id= "idSMT1" style= "Display:none" > Weak </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 "> No </span><span id=" idSMT2 "style=" Display:none "> Medium </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" > Strong </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" > excellent </span></td> </tr> </ Table> III, JS <script> function GetPassword () {var value = $ ("input[name= ' newpwd ')"). attr (' value '); $.get (' Index.php?r=account/testpwd ', {value:value},function (data) {if (Data>=1 &&Amp data<=3) {$ (' #idSM1 '). attr (' class ', ' PwdChkCon1 ');//Weak $ (' #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) { //medium $ (' #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) { //strong $ (' #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) { //extremely good $ (' #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 (); } }); Four, 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>  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.