Web page Password strength Detection instance code

Source: Internet
Author: User
Tags array object return string

Imitation MSN Password strength detection

The following JS file code:
var knocanonicalcounterpart = 0;
var kcapitalletter = 0;
var ksmallletter = 1;
var kdigit = 2;
var kpunctuation = 3;
var kalpha = 4;
var kcanonicalizelettersonly = true;
var kcananicalizeeverything = false;
var gdebugoutput = null;
var kdebugtracelevelnone = 0;
var kdebugtracelevelsuperdetail = 120;
var kdebugtracelevelrealdetail = 100;
var kdebugtracelevelall = 80;
var kdebugtracelevelmost = 60;
var kdebugtracelevelfew = 40;
var kdebugtracelevelrare = 20;
var gdebugtracelevel = Kdebugtracelevelnone;
function DebugPrint ()
{
var string = "";
if (gdebugtracelevel && gdebugoutput &&
Debugprint.arguments && (DebugPrint.arguments.length > 1) && (Debugprint.arguments[0] <= Gdebugtracelevel))
{
for (var index = 1; index < DebugPrint.arguments.length; index++)
{
string + + Debugprint.arguments[index] + "";
}
String = + "<br>\n";
Gdebugoutput (string);
}
}
function Csimilaritymap ()
{
This.m_elements = "";
This.m_canonicalcounterparts = "";
}
function Similaritymap_add (element, Canonicalcounterpart)
{
This.m_elements + = element;
This.m_canonicalcounterparts + = Canonicalcounterpart;
}
function Similaritymap_lookup (Element)
{
var canonicalcounterpart = Knocanonicalcounterpart;
var index = this.m_elements.indexOf (element);
if (index >= 0)
{
Canonicalcounterpart = this.m_canonicalCounterparts.charAt (index);
}
Else
{
}
return canonicalcounterpart;
}
function Similaritymap_getcount ()
{
return this.m_elements.length;
}
CSIMILARITYMAP.PROTOTYPE.ADD = Similaritymap_add;
CSimilarityMap.prototype.Lookup = Similaritymap_lookup;
CSimilarityMap.prototype.GetCount = Similaritymap_getcount;
function cdictionaryentry (length, wordlist)
{
this.m_length = length;
This.m_wordlist = wordlist;
}
function Dictionaryentry_lookup (Strword)
{
var ffound = false;
if (strword.length = = this.m_length)
{
var nfirst = 0;
var nlast = this.m_wordlist.length-1;
while (Nfirst <= nlast)
{
var ncurrent = Math.floor ((Nfirst + nlast)/2);
if (Strword = = This.m_wordlist[ncurrent])
{
Ffound = true;
Break
}
else if (Strword > This.m_wordlist[ncurrent])
{
Nlast = nCurrent-1;
}
Else
{
Nfirst = ncurrent + 1;
}
}
}
return ffound;
}
CDictionaryEntry.prototype.Lookup = Dictionaryentry_lookup;
function CDictionary ()
{
This.m_entries = new Array ()
}
function Dictionary_lookup (Strword)
{
for (var index = 0; index < this.m_entries.length; index++)
{
if (This.m_entries[index). Lookup (Strword))
{
return true;
}
}
}
function Dictionary_add (length, wordlist)
{
var il=this.m_entries.length;
var cd=new cdictionaryentry (length, wordlist)
THIS.M_ENTRIES[IL]=CD;
}
CDictionary.prototype.Lookup = Dictionary_lookup;
CDICTIONARY.PROTOTYPE.ADD = Dictionary_add;
var gsimilaritymap = new Csimilaritymap ();
var gdictionary = new CDictionary ();
function Charactersetchecks (type, fresult)
{
This.type = type;
This.fresult = Fresult;
}
function Isctype (character, type, ndebuglevel)
{
var fresult = false;
Switch (type)
{
Case Kcapitalletter:
if ((character >= ' A ') && (character <= ' Z '))
{
Fresult = true;
}
Break
Case Ksmallletter:
if ((character >= ' a ') && (character <= ' z '))
{
Fresult = true;
}
Break
Case Kdigit:
if ((character >= ' 0 ') && (character <= ' 9 '))
{
Fresult = true;
}
Break
Case Kpunctuation:
if ("!@#$%^&* () _+-= ' \";: [{]}\|. >,</"~" indexOf (character) >= 0)
{
Fresult = true;
}
Break
Case Kalpha:
if (Isctype (character, kcapitalletter) | | | isctype (character, Ksmallletter))
{
Fresult = true;
}
Break
Default
Break
}
return fresult;
}
function Canonicalizeword (Strword, Similaritymap, flettersonly)
{
var canonicalcounterpart = Knocanonicalcounterpart;
var strcanonicalizedword = "";
var nstringlength = 0;
if ((Strword!= null) && (strword.length > 0))
{
Strcanonicalizedword = Strword;
Strcanonicalizedword = Strcanonicalizedword.tolowercase ();
if (Similaritymap.getcount () > 0)
{
Nstringlength = Strcanonicalizedword.length;
for (var index = 0; index < nstringlength; index++)
{
if (flettersonly &&!isctype (Strcanonicalizedword.charat (index), Ksmallletter, Kdebugtracelevelsuperdetail) )
{
Continue
}
Canonicalcounterpart = Similaritymap.lookup (Strcanonicalizedword.charat (index));
if (Canonicalcounterpart!= knocanonicalcounterpart)
{
Strcanonicalizedword = strcanonicalizedword.substring (0, index) + Canonicalcounterpart +
Strcanonicalizedword.substring (index + 1, nstringlength);
}
}
}
}
return Strcanonicalizedword;
}
function Islongenough (Strword, Natleastthislong)
{
if ((Strword = null) | | isNaN (NATLEASTTHISLONG))
{
return false;
}
else if (Strword.length < Natleastthislong)
{
return false;
}
return true;
}
function Spansenoughcharactersets (Strword, Natleastthismany)
{
var ncharsets = 0;
var charactersetchecks = new Array (
New Charactersetchecks (Kcapitalletter, False),
New Charactersetchecks (Ksmallletter, False),
New Charactersetchecks (Kdigit, False),
New Charactersetchecks (Kpunctuation, False)
);
if ((Strword = null) | | isNaN (natleastthismany))
{
return false;
}
for (var index = 0; index < strword.length; index++)
{
for (var ncharset = 0; Ncharset < charactersetchecks.length;ncharset++)
{
if (!charactersetchecks[ncharset].fresult && isctype (Strword.charat (index), charactersetchecks[ncharset). Type, Kdebugtracelevelall))
{
Charactersetchecks[ncharset].fresult = true;
Break
}
}
}
for (var ncharset = 0; Ncharset < charactersetchecks.length;ncharset++)
{
if (Charactersetchecks[ncharset].fresult)
{
ncharsets++;
}
}
if (Ncharsets < Natleastthismany)
{
return false;
}
return true;
}
function Foundindictionary (Strword, Similaritymap, dictionary)
{
var strcanonicalizedword = "";
if ((Strword = null) | | (Similaritymap = null) | | (dictionary = null))
{
return true;
}
Strcanonicalizedword = Canonicalizeword (Strword, Similaritymap, kcanonicalizelettersonly);
if (dictionary. Lookup (Strcanonicalizedword))
{
return true;
}
return false;
}
function Isclosevariationofawordindictionary (Strword, Threshold, Similaritymap, dictionary)
{
var strcanonicalizedword = "";
var nminimummeaningfulmatchlength = 0;
if ((Strword = null) | | isNaN (threshold) | | (Similaritymap = null) | | (dictionary = null))
{
return true;
}
Strcanonicalizedword = Canonicalizeword (Strword, Similaritymap, kcananicalizeeverything);
Nminimummeaningfulmatchlength = Math.floor (threshold) * strcanonicalizedword.length);
for (var nsubstringlength = strcanonicalizedword.length; nsubstringlength >= nminimummeaningfulmatchlength; nsubstringlength--)
{
for (var nsubstringstart = 0; (Nsubstringstart + nminimummeaningfulmatchlength) < strcanonicalizedword.length; nsubstringstart++)
{
var Strsubword = Strcanonicalizedword.substr (Nsubstringstart, nsubstringlength);
if (dictionary. Lookup (Strsubword))
{
return true;
}
}
}
return false;
}
function Clientsidestrongpassword ()
{
Return (Islongenough (Clientsidestrongpassword.arguments[0], "7") &&
Spansenoughcharactersets (Clientsidestrongpassword.arguments[0], "3") &&
(! (Isclosevariationofawordindictionary (Clientsidestrongpassword.arguments[0], "0.6",
CLIENTSIDESTRONGPASSWORD.ARGUMENTS[1]));
}
function Clientsidemediumpassword ()
{
Return (Islongenough (Clientsidemediumpassword.arguments[0], "7") &&
Spansenoughcharactersets (Clientsidemediumpassword.arguments[0], "2") &&
(! (Foundindictionary (Clientsidemediumpassword.arguments[0], clientsidemediumpassword.arguments[1],
CLIENTSIDEMEDIUMPASSWORD.ARGUMENTS[2])));
}
function Clientsideweakpassword ()
{
Return (Islongenough (Clientsideweakpassword.arguments[0], "6") | |
(! (Islongenough (clientsideweakpassword.arguments[0], "0")));
}
function Geid (SID) {return document.getElementById (SID);}
Function evalpwdstrength (OF,SP) {padpasswd (of,sp.length*2); if (Clientsidestrongpassword, Gdictionary)) {disppwdstrength (3, ' css0165 ');} Else if (Clientsidemediumpassword (sp,gsimilaritymap,gdictionary)) {disppwdstrength (2, ' css0164 ');} Else if (Clientsideweakpassword (sp,gsimilaritymap,gdictionary)) {disppwdstrength (1, ' css0163 ');} Else{disppwdstrength (0, ' css0162 ');} Function setpwdstrengthex (OF,SP) {evalpwdstrength (OF,SP); if (Clientsidestrongpassword, Gdictionary)) {document.cookie= "pwdstrength=3";} Else if (Clientsidemediumpassword (sp,gsimilaritymap,gdictionary)) {document.cookie= "pwdstrength=2";} Else if (Clientsideweakpassword (sp,gsimilaritymap,gdictionary)) {document.cookie= "pwdstrength=1";} Else{document.cookie= "Pwdstrength=0";} Function setpwdstrength (sp,of) {if (Clientsidestrongpassword (sp,gsimilaritymap,gdictionary)) {oF.value  = 3;} Else if (Clientsidemediumpassword (sp,gsimilaritymap,gdictionary)) {of.value = 2;} ElSe if (Clientsideweakpassword (sp,gsimilaritymap,gdictionary)) {of.value = 1;} ELSE{OF.VALUE&NBSP;=&NBSP;0}} Function xpwcont () {if  (typeof (Parent.opener.RegistrationFinishedCallback)!= "undefined") { Parent.opener.RegistrationFinishedCallback ();} Parent.close ();} Function onsigninsubmit (OF) {if (G_fas) {return false;} if (typeof of!= "Object") {Return false} Var bl=true,bp=true,bi=true,bh=true;bl=val (Of.login); Var sem=of.login.value;bl=valem (SEM); if (typeof  of.passwd== "Object") {Bp=val (OF.PASSWD);} if (typeof of.pin== "Object") {Bi=val (of.pin);} if (typeof of.hipsolution== "Object") {Bh=val (of.hipsolution);} if (!bl| |! bp| |! bi| |! BH) {var fsf=true;var ae=["i0518", "i0519", "i0512", "i0527", "i0545", "i0562", "i0517"]; Hdivs (AE); if (!BL) {fsf=swerr ("i0519", OF.LOGIN,FSF)};if (!bi) {fsf=swerr ("i0527", OF.PIN,FSF)};if (!BH) {Fsf=swerr (" i0517 ", OF.HIPSOLUTION,FSF)};if (!BP) {fsf=swerr (" i0512 ", OF.PASSWD,FSF)};return false;} if (typeof of.passwd== "objecT ") {PADPASSWD (of,of.passwd.value.length);} if (typeof g_do!= "undefined") {Var dom=sem.substr (Sem.indexof (' @ ') +1); var su=g_do[dom.tolowercase ()];if (SU) {OF.ACTION=SU}} if (typeof g_qs!= "undefined") {if (G_qs) {var ss= "&"; if (oF.action.indexOf ('? ') ==-1) {ss= "?";} if (OF.action.indexOf (G_QS) ==-1) {Of.action+=ss+g_qs;}}} G_fas=true;of.login.value=of.login.value.tolowercase (); Of.submit (); return false;} Function onpadsubmit (OF) {if (typeof of.currpw== "Object") {padpasswd (of,of.currpw.value.length);} Of.submit (); return false;} Function onpadsubmitwithaction (Of,szu) {if (typeof of.currpw== "Object") {padpasswd (OF, OF.CurrPW.value.length);} Return onsubmitwithaction (Of,szu);} FUNCTION&NBSP;PADPASSWD (OF,LPWD) {if (typeof of.pwdpad== "Object") {var spad= " Ifyouarereadingthisyouhavetoomuchfreetime "; var lpad=spad.length-lpwd;of.pwdpad.value=spad.substr (0, LPad <0)? 0:lpad);} Function hdivs (AE) {for (var i=0;i<ae.length;++i) {Var o=geid (Ae[i]); if (o) {o.style.display= "none";}}} Function swerr (SID,OFN,FSF) {Geid (SID). style.display= "Block"; if (FSF) {ofn.focus (); Ofn.select ();} return false;
}

The following is the CSS file code:
. css0162
{background-color: #EBEBEB; border-right:solid 1px #BEBEBE; 1px #BEBEBE border-bottom:solid;}
. css0163
{background-color: #FF4545; border-right:solid 1px #BB2B2B; 1px #BB2B2B border-bottom:solid;}
. css0164
{background-color: #FFD35E; border-right:solid 1px #E9AE10; 1px #E9AE10 border-bottom:solid;}
. css0165
{background-color: #3ABB1C; border-right:solid 1px #267A12; 1px #267A12 border-bottom:solid;}

The following is a form page code:
<link rel= "stylesheet" type= "Text/css" href= "Webblue1033.css"/>
<script type= "Text/javascript" src= "Pswdplc.js" ></script>
<form name= "Regprofileform" style= "margin:0px" method= "POST" target= "_self" >
Password:
<input name= "p3e8" type= "password" id= "Id3e8_9" maxlength= "autocomplete=" Off "value=" "style=" Ime-mode: Disabled "class=" css0081 "onkeyup=" Javascript:setpwdstrengthex (document.forms[0],this.value); "/>
<br/>
<script type= "Text/javascript" >
function Disppwdstrength (IN,SHL)
{if (in>3) {in=3} for (Var i=0;i<4;i++) {var shcr= "css0162"; if (i<=in) {SHCR=SHL;} if (i>0) {Geid ("IDSM" +i). CLASSNAME=SHCR; Geid ("Idsmt" +i). style.display= ((i==in)? " Inline ": none");}
</script>
<table cellpadding= "0"  cellspacing= "0"  class= "css0161"  style= "height:19px" ><tr ><td id= "idSM1"  width= "33%"  class= "css0162" Center " align=" font-size:1px "> </span><span id=" idSMT1 " style=" display:none; > Weak </span></td><td id= "idSM2"  width= "34%"  class= "css0162"  align= "center"  style= "border-left:solid 1px  #fff" ><span style= "font-size:1px" > </span ><span id= "idSMT0"  style= "Display:inline;font-weight:normal;color: #666" >not rated</ Span><span id= "idSMT2"  style= "Display:none;" > </span></td><td id= "idSM3"  width= "33%"  class= "css0162"  align= "center"  style= "border-left:solid 1px  #fff" ><span style= "font-size:1px" > </span ><span id= "idSMT3"  style= "Display:none;" > Strong </span></td></tR></table>



Related Article

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.