The password is already an indispensable tool in our lives, but an unsafe password may have unnecessary losses to us. As a website designer, if we can securely evaluate the password entered in the web page, and display the corresponding prompt information, it will help the user set a secure password. At the same time, the site is more human and is more attractive.
What is a secure password? This program evaluates in the following ways.
1. If the password is less than 5, then it is considered to be a weak password.
2. If the password consists only of a number, lowercase letters, uppercase letters, or other special symbols, it is considered to be a weak password.
3. If the password consists of two components of numbers, lowercase letters, uppercase letters, or other special symbols, it is considered a moderately secure password.
4. If the password consists of three or more of the numbers, lowercase letters, uppercase letters, or other special symbols, it is considered to be a relatively secure password.
This program will display different colors according to the password input by the user, and the specific procedure is as follows (demo address: http://www.web9898.cn/reg):
// charmode function
// Test which class belongs to a character.
Function charmode (in) {
IF (in> = 48 && in <= 57) // number
Return 1;
IF (in> = 65 && in <= 90) // uppercase letters
Return 2;
IF (in> = 97 && in <= 122) // lowercase
Return 4;
Else
Return 8; // Special characters
}
// bittotal function
/ / How many modes are calculated in the current password
Function bittotal (NUM) {
MODES = 0;
For (i = 0; i <4; i ) {
IF (NUM & 1) MODES ;
Num >>> = 1;
}
Return model;
}
// checkstrong function
/ / Return to the strength level of the password
Function checkstrong (SPW) {
IF (spw.length <= 4)
Return 0; // password too short
MODES = 0;
For (i = 0; i // Test the category of each character and count how many modes. Modes | = Charmode (spw.charcodeat (i)); } Return Bittotal (MODES); } // PWSTRENGTH function // Show different colors according to different levels when the user is disconnected by the keyboard or password input box 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.getlementByid ("strength_l"). style.Background = lcolor; Document.getlementByid ("strength_m"). style.Background = mcolor; Document.getlementByid ("strength_h"). style.Background = Hcolor; Return; } script>
TR>
TABLE>
form>