JS Check Password strength

Source: Internet
Author: User

Online reprint of a piece of code, save for later use,

JS file:

Determine the type of password entered
function Charmode (in) {
if (in>=48 && in <=57)//Digital
return 1;
if (in>=65 && in <=90)//Uppercase
return 2;
if (in>=97 && in <=122)//lowercase
return 4;
Else
return 8;
}
Bittotal function
Calculate password mode
function Bittotal (num) {
modes=0;
for (i=0;i<4;i++) {
if (num & 1) modes++;
num>>>=1;
}
return modes;
}
Return strength level
function Checkstrong (SPW) {
if (spw.length<=4)
return 0; The password is too short
modes=0;
for (i=0;i<spw.length;i++) {
Password mode
Modes|=charmode (Spw.charcodeat (i));
}
Return Bittotal (Modes);
}

Display Color
function Pwstrength (pwd) {
O_color= "#eeeeee";
L_color= "#FF0000";
M_color= "#FF9900";
H_color= "#33CC00";
if (pwd==null| | pwd== ') {
Lcolor=mcolor=hcolor=o_color;
}
else{
S_level=checkstrong (PWD);
Switch (s_level) {
Case 0:
Lcolor=mcolor=hcolor=o_color;
Case 1:
Lcolor=l_color;
Mcolor=hcolor=o_color;
Break
Case 2:
Lcolor=mcolor=m_color;
Hcolor=o_color;
Break
Default
Lcolor=mcolor=hcolor=h_color;
}
}
document.getElementById ("strength_l"). Style.background=lcolor;
document.getElementById ("Strength_m"). Style.background=mcolor;
document.getElementById ("Strength_h"). Style.background=hcolor;
Return
}

Page:

<td>
<table border= "0" &GT;&LT;TR >
&LT;TD style= "padding:0px;border-top-width:0px; Border-right: #ff0000 0px solid; Border-left: #ff0000 0px solid; Border-top-color: #ff0000; Border-bottom: #ff0000 0px solid; " >

<input id= "password" name= "password" Type=password size=8 onkeyup=pwstrength (this.value) onblur=pwstrength ( This.value) ></td>
&LT;TD style= "padding:0px;border-top-width:0px; Border-right: #ff0000 0px solid; Border-left: #ff0000 0px solid; Border-top-color: #ff0000; Border-bottom: #ff0000 0px solid; " >
<span id= "Sp_6" style= "color:red;" ></span>
</td>
&LT;TD style= "padding:0px;border-top-width:0px; Border-right: #ff0000 0px solid; Border-left: #ff0000 0px solid; Border-top-color: #ff0000; Border-bottom: #ff0000 0px solid; " >
<table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 1 "bordercolor=" #eeeeee "height=" style= "Display: Inline ' >
&LT;TR align= "center" bgcolor= "#f5f5f5" >
&LT;TD width= "33%" id= "strength_l" > Weak </td>
&LT;TD width= "33%" id= "Strength_m" > </td>
&LT;TD width= "33%" id= "Strength_h" > Strong </td>
</tr>
</table>
</td>
</tr>
</table>
</td>

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.