Conversion (JS password strength)

Source: Internet
Author: User
< 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 >

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.