Detailed explanation of PHP's method for determining password strength, and detailed explanation of php's method for determining password strength

Source: Internet
Author: User

Detailed explanation of PHP's method for determining password strength, and detailed explanation of php's method for determining password strength

This article describes how to determine the password strength of PHP. We will share this with you for your reference. The details are as follows:

I. 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 (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;

Ii. html page

<Table cellspacing = "0" cellpadding = "0"> <tr> <td> enter the password: </td> <td colspan = "4"> <input type = "password" value = "" name = "newpwd" onblur = "getPassword (); "/> </tr> <td> password strength: </td> <td id = "idSM1" align = "middle" width = "20%"> <span style = "height: 0px; 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 "> none </span> <span id =" idSMT2 "style =" DISPLAY: none "> moderate </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 & 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) {// excellent $ ('# 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 ();}});}

Iv. 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: here we will provide several related online tools for your reference:

Online Password Security Detection:
Http://tools.jb51.net/password/my_password_safe

Online random number/string generation tool:
Http://tools.jb51.net/aideddesign/suijishu

High-strength Password generator:
Http://tools.jb51.net/password/CreateStrongPassword

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.