Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  javascript  >  正文 javascript密码强度实时检测实例代码

javascript密码强度实时检测实例代码

发布时间:2017-01-11   编辑:www.jquerycn.cn
jquery中文网为您提供javascript密码强度实时检测实例代码等资源,欢迎您收藏本站,我们将为您提供最新的javascript密码强度实时检测实例代码资源
这是一篇算是原创的javascript密码强度实时检测实例代码的,他可以根据用户输入的密码来判断强度为中,低,高三个等级提示,有需要的朋友可以看看哦。
<script>ec(2);</script>
提示:您可以先修改部分代码再运行

<textarea name="runcool" rows="28" cols="75" > <tr bgcolor="#FFFFFF"> <td height="30" align="right" nowrap>* 设定密码:</td> <td nowrap></td><td id="regpassinfo" class="noshow" style="margin:2px 0px;"></td> </tr> <tr bgcolor="#FFFFFF"> <td height="30" align="right" nowrap>密码强度:</td> <td colspan="2"> <table border="0" width="250" cellspacing="0" cellpadding="2"> <tr> <td id=iWeak align="center" bgcolor="#f1f1f1" style="COLOR: #adadad;BORDER-RIGHT: #dedede 1px solid">弱</td> <td id=iMedium align="center" bgcolor="#f1f1f1" style="COLOR: #adadad;BORDER-RIGHT: #dedede 1px solid">中</td> <td id=iStrong align="center" bgcolor="#f1f1f1" style="COLOR: #adadad;">强</td> </tr> </table> </td> </tr> <tr bgcolor="#FFFFFF"> <td height="25" align="right">* 确认密码:</td> <td></td><td id="regpass2info" class="noshow"></td> </tr> <tr bgcolor="#FFFFFF"><td height="5" colspan="3"></td></tr> <script language="javascript"> function GEId(sID) { try{return document.getElementById(sID)}catch(e){}; } function EvalPwd(sP) { var aPQ=new Array(6); if(ClientSideStrongPassword(sP,gSimilarityMap,gDictionary)) { aPQ=["#0c6","#0c6","#0c6","#0c6","#0c6","#000"]; } else if(ClientSideMediumPassword(sP,gSimilarityMap,gDictionary)) { aPQ=["#ff9","#ff9","#F1F1F1","#ff9","#000","#adadad"]; } else if(ClientSideWeakPassword(sP,gSimilarityMap,gDictionary)) { aPQ=["#f00","#F1F1F1","#F1F1F1","#000","#adadad","#adadad"]; } else { aPQ=["#F1F1F1","#F1F1F1","#F1F1F1","#adadad","#adadad","#adadad"]; } var oW=GEId("iWeak").style; var oM=GEId("iMedium").style; var oS=GEId("iStrong").style; oW.background=aPQ[0]; oM.background=aPQ[1]; oS.background=aPQ[2]; oW.color=aPQ[3]; oM.color=aPQ[4]; oS.color=aPQ[5]; } 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 kDebugTraceLevelNone = 0; var kDebugTraceLevelSuperDetail = 120; var kDebugTraceLevelRealDetail = 100; var kDebugTraceLevelAll = 80; var kDebugTraceLevelMost = 60; var kDebugTraceLevelFew = 40; var kDebugTraceLevelRare = 20; var gDebugTraceLevel = kDebugTraceLevelNone; 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 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 ("!@#$%^&*()_ -='";:[{]}|.>,= 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], ClientSideStrongPassword.arguments[2])))); } 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")))); } </script></td> </tr> </table></textarea>
提示:您可以先修改部分代码再运行

您可能感兴趣的文章:
JS检测密码强度(密码过短、密码强度良好、密码强度高)
js 验证密码强度的例子
passwordStrength 基于jquery的密码强度检测代码使用介绍
js检测密码强度 js验证密码强度的原生代码
js验证密码强度 js检测密码强度的类
jQuery密码强度提示插件 Complexify
jQuery密码强度提示插件 Complexify
js检测密码强度的代码(附效果图)
js 验证密码强度的代码分享
js验证密码强度的脚本

[关闭]