Web page Password Strength Verification script

Source: Internet
Author: User
Tags lowercase

Passwords are an essential tool in our life and work, but an unsafe password may cause unnecessary loss. As a web designer, if we can make a security assessment of the password entered by the user in the Web page and display the corresponding prompts, it will be helpful to set a secure password for the user. At the same time make the site more humane, more attractive.

What is a secure password? This procedure is evaluated in the following manner.

1. If the password is less than 5 digits, it is considered a weak password.

2. If the password is made up of only one of the numbers, lowercase letters, capitals, or other special symbols, it is considered a weak password.

3. If the password is composed of numbers, lowercase letters, capitals, or other special symbols, it is considered to be a moderate security password.

4. If the password consists of more than three of the numbers, lowercase letters, capitals, or other special symbols, it is considered a safe password.

This program will be based on the user entered the password to display different colors to indicate the strength of the password, the specific procedures are as follows:

Passwords are an essential tool in our life and work, but an unsafe password may cause unnecessary loss. As a web designer, if we can make a security assessment of the password entered by the user in the Web page and display the corresponding prompts, it will be helpful to set a secure password for the user. At the same time make the site more humane, more attractive.

What is a secure password? This procedure is evaluated in the following manner.

1. If the password is less than 5 digits, it is considered a weak password.

2. If the password is made up of only one of the numbers, lowercase letters, capitals, or other special symbols, it is considered a weak password.

3. If the password is composed of numbers, lowercase letters, capitals, or other special symbols, it is considered to be a moderate security password.

4. If the password consists of more than three of the numbers, lowercase letters, capitals, or other special symbols, it is considered a safe password.

This program will be based on the user entered the password to display different colors to indicate the strength of the password, the specific procedures are as follows:

The following is a reference fragment:


<scriptlanguage=javascript>

Charmode function
Test what kind of character it belongs to.
Functioncharmode (in) {
if (in>=48&&in<=57)//number
RETURN1;
if (in>=65&&in<=90)/capital Letter
return2;
if (in>=97&&in<=122)//lowercase
RETURN4;
Else
return8;//Special Characters
}

Bittotal function
Calculates how many patterns there are in the current password
Functionbittotal (num) {
modes=0;
for (i=0;i<4;i++) {
if (num&1) modes++;
num>>>=1;
}
Returnmodes;
}

Checkstrong function
Returns the strength level of a password

Functioncheckstrong (SPW) {
if (spw.length<=4)
return0;//Password is too short
modes=0;
for (i=0;i<spw.length;i++) {
Test the category of each character and count how many patterns there are.
Modes|=charmode (Spw.charcodeat (i));
}

Returnbittotal (Modes);

}

Pwstrength function
Displays different colors at different levels when the user releases the keyboard or password input box from losing focus

Functionpwstrength (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) {
CASE0:
Lcolor=mcolor=hcolor=o_color;
CASE1:
Lcolor=l_color;
Mcolor=hcolor=o_color;
Break
CASE2:
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
}

</script>

<formname=form1action= "" >
Enter Password:
<inputtype=passwordsize=10onkeyup=pwstrength (This.value)
Onblur=pwstrength (This.value) >
<br> Password Strength:
<tablewidth= "217" border= "1" cellspacing= "0" cellpadding= "1" bordercolor= "#cccccc"
height= "Style=display:inline>"
<tralign= "center" bgcolor= "#eeeeee" >

<tdwidth= "33%" id= "strength_l" > Weak </td>

<tdwidth= "33%" id= "Strength_m" > </td>

<tdwidth= "33%" id= "Strength_h" > Strong </td>
</tr>
</table>

</form>



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.