< Script Type = " Text/JavaScript " >
VaR Passwordstrength = {
Level :[ " Excellent " , " Average " , " Relatively weak " , " Too short " ], // Strength prompt information
Levelvalue :[ 15 , 10 , 5 , 0 ], // The intensity value corresponding to the preceding prompt.
Factor :[ 1 , 2 , 5 ], // The number of weighted values, including letters, numbers, and others.
Kindfactor :[ 0 , 0 , 10 , 20 ], // The password includes several weights.
RegEx :[ / [ - Za - Z] / G, / \ D / G, / [ ^ A - Za - Z0 - 9 ] / G] // Character, number, non-character number (I .e. special symbol)
}
Passwordstrength. strengthvalue = Function (PWD)
{
VaR Strengthvalue = 0 ;
VaR Composedkind = 0 ;
For ( VaR I = 0 ; I < This . RegEx. length; I ++ )
{
VaR Chars = PWD. Match ( This . RegEx [I]); // Matches the characters that match the specified Regular Expression in the current password. If multiple characters are separated by commas (,),
If (Chars ! = Null )
{
Strengthvalue + = Chars. Length * This . Factor [I];
Composedkind ++ ;
}
}
Strengthvalue + = This . Kindfactor [composedkind];
Return Strengthvalue;
}
Passwordstrength. strengthlevel = Function (PWD)
{
VaR Value = This . Strengthvalue (PWD );
For ( VaR I = 0 ; I < This . Levelvalue. length; I ++ )
{
If (Value > = This . Levelvalue [I])
Return This . Level [I];
}
}
Function Loadinputcontext (o)
{
VaR Showmsg = Passwordstrength. strengthlevel (O. value );
Switch (Showmsg)
{
Case " Too short " : Showmsg + = " /> " ;
Break ;
Case " Relatively weak " : Showmsg + = " /> " ;
Break ;
Case " Average " : Showmsg + = " /> " ;
Break ;
Case " Excellent " : Showmsg + = " /> " ;
Break ;
}
Document. getelementbyid ('showmsg '). innerhtml = Showmsg;
}
</ Script >
< Input Name = "Password" Type = "Password" ID = "Password" Size = "20" Onkeyup = "Return loadinputcontext (this );" />
< Span ID = "Showmsg" > </ Span >