JS realizes the function of displaying security bar according to password length
- 2021-08-03 08:04:18
- OfStack
You can often see that the digital password will display the security bar function according to the length of the password entered on 1 website. How is this function realized based on js? Let's look at the implementation code, which is as follows:
// Display security bar according to password length
<ul class="clear">
<li> Password: </li>
<li> <input type="password" id="pwd" name="pwd" class="in" onKeyUp=pwStrength(this.value) onBlur=pw_y("pwd","pwd1")></li>
<li><em class="red">*</em></li>
<li class="i2 grey"><table border="0" bordercolor="#cccccc" style='display:marker'>
<tr align="center">
<td id="strength_L" bgcolor="#eeeeee"> Weak </td>
<td id="strength_M" bgcolor="#eeeeee"> Medium </td>
<td id="strength_H" bgcolor="#eeeeee"> Strong </td>
<td align="left" >
<label id="pwd1"> Use numbers, letters, underscores, and lengths in 6 - 20 Between characters </label></td>
</tr>
</table>
</li>
</ul>
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;
}