Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[插件] 注册页面增加"MSN密码强度" for all Dz

[复制链接]
谨少爷 发表于 2005-12-12 19:35:54 | 显示全部楼层 |阅读模式
在落伍者论坛看"给你网站的注册项中增加"密码强度" 来托出网站的亲和力"
无聊一下也放在自己的论坛的注册页面上....下面修改仅供参考!
演示:http://bbs.yinyuegame.com/register.php  (自己注册试试)

1.将以下代码保存为 pswdplc.js 放在include文件中
  1. var kNoCanonicalCounterpart = 0;
  2. var kCapitalLetter = 0;
  3. var kSmallLetter = 1;
  4. var kDigit = 2;
  5. var kPunctuation = 3;
  6. var kAlpha =  4;
  7. var kCanonicalizeLettersOnly = true;
  8. var kCananicalizeEverything = false;
  9. var gDebugOutput = null;
  10. var kDebugTraceLevelNone = 0;
  11. var kDebugTraceLevelSuperDetail = 120;
  12. var kDebugTraceLevelRealDetail = 100;
  13. var kDebugTraceLevelAll = 80;
  14. var kDebugTraceLevelMost = 60;
  15. var kDebugTraceLevelFew = 40;
  16. var kDebugTraceLevelRare = 20;
  17. var gDebugTraceLevel = kDebugTraceLevelNone;
  18. function DebugPrint()
  19. {
  20. var string = "";
  21. if (gDebugTraceLevel && gDebugOutput &&
  22. DebugPrint.arguments && (DebugPrint.arguments.length > 1) && (DebugPrint.arguments[0] <= gDebugTraceLevel))
  23. {
  24. for(var index = 1; index < DebugPrint.arguments.length; index++)
  25. {
  26. string += DebugPrint.arguments[index] + " ";
  27. }
  28. string += "<br>\n";
  29. gDebugOutput(string);
  30. }
  31. }
  32. function CSimilarityMap()
  33. {
  34. this.m_elements = "";
  35. this.m_canonicalCounterparts = "";
  36. }
  37. function SimilarityMap_Add(element, canonicalCounterpart)
  38. {
  39. this.m_elements += element;
  40. this.m_canonicalCounterparts += canonicalCounterpart;
  41. }
  42. function SimilarityMap_Lookup(element)
  43. {
  44. var canonicalCounterpart = kNoCanonicalCounterpart;
  45. var index = this.m_elements.indexOf(element);
  46. if (index >= 0)
  47. {
  48. canonicalCounterpart = this.m_canonicalCounterparts.charAt(index);
  49. }
  50. else
  51. {
  52. }
  53. return canonicalCounterpart;
  54. }
  55. function SimilarityMap_GetCount()
  56. {
  57. return this.m_elements.length;
  58. }
  59. CSimilarityMap.prototype.Add = SimilarityMap_Add;
  60. CSimilarityMap.prototype.Lookup = SimilarityMap_Lookup;
  61. CSimilarityMap.prototype.GetCount = SimilarityMap_GetCount;
  62. function CDictionaryEntry(length, wordList)
  63. {
  64. this.m_length = length;
  65. this.m_wordList = wordList;
  66. }
  67. function DictionaryEntry_Lookup(strWord)
  68. {
  69. var fFound = false;
  70. if (strWord.length == this.m_length)
  71. {
  72. var nFirst = 0;
  73. var nLast = this.m_wordList.length - 1;
  74. while( nFirst <= nLast )
  75. {
  76. var nCurrent = Math.floor((nFirst + nLast)/2);
  77. if( strWord == this.m_wordList[nCurrent])
  78. {
  79. fFound = true;
  80. break;
  81. }
  82. else if ( strWord > this.m_wordList[nCurrent])
  83. {
  84. nLast = nCurrent - 1;
  85. }
  86. else
  87. {
  88. nFirst = nCurrent + 1;
  89. }
  90. }
  91. }

  92. return fFound;
  93. }
  94. CDictionaryEntry.prototype.Lookup = DictionaryEntry_Lookup;
  95. function CDictionary()
  96. {
  97. this.m_entries = new Array()
  98. }
  99. function Dictionary_Lookup(strWord)
  100. {
  101. for (var index = 0; index < this.m_entries.length; index++)
  102. {
  103. if (this.m_entries[index].Lookup(strWord))
  104. {
  105. return true;
  106. }
  107. }
  108. }
  109. function Dictionary_Add(length, wordList)
  110. {
  111. var iL=this.m_entries.length;
  112. var cD=new CDictionaryEntry(length, wordList)
  113. this.m_entries[iL]=cD;
  114. }
  115. CDictionary.prototype.Lookup = Dictionary_Lookup;
  116. CDictionary.prototype.Add = Dictionary_Add;
  117. var gSimilarityMap = new CSimilarityMap();
  118. var gDictionary = new CDictionary();
  119. function CharacterSetChecks(type, fResult)
  120. {
  121. this.type = type;
  122. this.fResult = fResult;
  123. }
  124. function isctype(character, type, nDebugLevel)
  125. {
  126. var fResult = false;
  127. switch(type)
  128. {
  129. case kCapitalLetter:
  130. if((character >= 'A') && (character <= 'Z'))
  131. {
  132. fResult = true;
  133. }
  134. break;
  135. case kSmallLetter:
  136. if ((character >= 'a') && (character <= 'z'))
  137. {
  138. fResult = true;
  139. }
  140. break;
  141. case kDigit:
  142. if ((character >= '0') && (character <= '9'))
  143. {
  144. fResult = true;
  145. }
  146. break;
  147. case kPunctuation:
  148. if ("!@#$%^&*()_+-='";:[{]}\|.>,</?`~".indexOf(character) >= 0)
  149. {
  150. fResult = true;
  151. }
  152. break;
  153. case kAlpha:
  154. if (isctype(character, kCapitalLetter) || isctype(character, kSmallLetter))
  155. {
  156. fResult = true;
  157. }
  158. break;
  159. default:
  160. break;
  161. }

  162. return fResult;
  163. }
  164. function CanonicalizeWord(strWord, similarityMap, fLettersOnly)
  165. {
  166. var canonicalCounterpart = kNoCanonicalCounterpart;
  167. var strCanonicalizedWord = "";
  168. var nStringLength = 0;
  169. if ((strWord != null) && (strWord.length > 0))
  170. {
  171. strCanonicalizedWord = strWord;
  172. strCanonicalizedWord = strCanonicalizedWord.toLowerCase();

  173. if (similarityMap.GetCount() > 0)
  174. {
  175. nStringLength = strCanonicalizedWord.length;

  176. for(var index = 0; index < nStringLength; index++)
  177. {
  178. if (fLettersOnly && !isctype(strCanonicalizedWord.charAt(index), kSmallLetter, kDebugTraceLevelSuperDetail))
  179. {
  180. continue;
  181. }

  182. canonicalCounterpart = similarityMap.Lookup(strCanonicalizedWord.charAt(index));
  183. if (canonicalCounterpart != kNoCanonicalCounterpart)
  184. {
  185. strCanonicalizedWord = strCanonicalizedWord.substring(0, index) + canonicalCounterpart +
  186. strCanonicalizedWord.substring(index + 1, nStringLength);
  187. }
  188. }
  189. }
  190. }
  191. return strCanonicalizedWord;
  192. }
  193. function IsLongEnough(strWord, nAtLeastThisLong)
  194. {
  195. if ((strWord == null) || isNaN(nAtLeastThisLong))
  196. {
  197. return false;
  198. }
  199. else if (strWord.length < nAtLeastThisLong)
  200. {
  201. return false;
  202. }

  203. return true;
  204. }
  205. function SpansEnoughCharacterSets(strWord, nAtLeastThisMany)
  206. {
  207. var nCharSets = 0;
  208. var characterSetChecks = new Array(
  209. new CharacterSetChecks(kCapitalLetter, false),
  210. new CharacterSetChecks(kSmallLetter, false),
  211. new CharacterSetChecks(kDigit, false),
  212. new CharacterSetChecks(kPunctuation, false)
  213. );
  214. if ((strWord == null) || isNaN(nAtLeastThisMany))
  215. {
  216. return false;
  217. }

  218. for(var index = 0; index < strWord.length; index++)
  219. {
  220. for(var nCharSet = 0; nCharSet < characterSetChecks.length;nCharSet++)
  221. {
  222. if (!characterSetChecks[nCharSet].fResult && isctype(strWord.charAt(index), characterSetChecks[nCharSet].type, kDebugTraceLevelAll))
  223. {
  224. characterSetChecks[nCharSet].fResult = true;
  225. break;
  226. }
  227. }
  228. }
  229. for(var nCharSet = 0; nCharSet < characterSetChecks.length;nCharSet++)
  230. {
  231. if (characterSetChecks[nCharSet].fResult)
  232. {
  233. nCharSets++;
  234. }
  235. }

  236. if (nCharSets < nAtLeastThisMany)
  237. {
  238. return false;
  239. }

  240. return true;
  241. }
  242. function FoundInDictionary(strWord, similarityMap, dictionary)
  243. {
  244. var strCanonicalizedWord = "";

  245. if((strWord == null) || (similarityMap == null) || (dictionary == null))
  246. {
  247. return true;
  248. }
  249. strCanonicalizedWord = CanonicalizeWord(strWord, similarityMap, kCanonicalizeLettersOnly);

  250. if (dictionary.Lookup(strCanonicalizedWord))
  251. {
  252. return true;
  253. }

  254. return false;
  255. }
  256. function IsCloseVariationOfAWordInDictionary(strWord, threshold, similarityMap, dictionary)
  257. {
  258. var strCanonicalizedWord = "";
  259. var nMinimumMeaningfulMatchLength = 0;

  260. if((strWord == null) || isNaN(threshold) || (similarityMap == null) || (dictionary == null))
  261. {
  262. return true;
  263. }
  264. strCanonicalizedWord = CanonicalizeWord(strWord, similarityMap, kCananicalizeEverything);
  265. nMinimumMeaningfulMatchLength = Math.floor((threshold) * strCanonicalizedWord.length);
  266. for (var nSubStringLength = strCanonicalizedWord.length; nSubStringLength >= nMinimumMeaningfulMatchLength; nSubStringLength--)
  267. {
  268. for(var nSubStringStart = 0; (nSubStringStart + nMinimumMeaningfulMatchLength) < strCanonicalizedWord.length; nSubStringStart++)
  269. {
  270. var strSubWord = strCanonicalizedWord.substr(nSubStringStart, nSubStringLength);

  271. if (dictionary.Lookup(strSubWord))
  272. {
  273. return true;
  274. }
  275. }
  276. }
  277. return false;
  278. }

  279. function ClientSideStrongPassword()
  280. {
  281. return (IsLongEnough(ClientSideStrongPassword.arguments[0], "7") &&
  282. SpansEnoughCharacterSets(ClientSideStrongPassword.arguments[0], "3") &&
  283. (!(IsCloseVariationOfAWordInDictionary(ClientSideStrongPassword.arguments[0], "0.6",
  284. ClientSideStrongPassword.arguments[1], ClientSideStrongPassword.arguments[2]))));
  285. }

  286. function ClientSideMediumPassword()
  287. {
  288. return (IsLongEnough(ClientSideMediumPassword.arguments[0], "7") &&
  289. SpansEnoughCharacterSets(ClientSideMediumPassword.arguments[0], "2") &&
  290. (!(FoundInDictionary(ClientSideMediumPassword.arguments[0], ClientSideMediumPassword.arguments[1],
  291. ClientSideMediumPassword.arguments[2]))));
  292. }

  293. function ClientSideWeakPassword()
  294. {
  295. return (IsLongEnough(ClientSideWeakPassword.arguments[0], "6") ||
  296. (!(IsLongEnough(ClientSideWeakPassword.arguments[0], "0"))));
  297. }
  298. function GEId(sID){return document.getElementById(sID);}
  299. function EvalPwdStrength(oF,sP){PadPasswd(oF,sP.length*2);if(ClientSideStrongPassword(sP,gSimilarityMap,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(sP,gSimilarityMap,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 = 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 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;
  300. }
复制代码


2.查找templates\default\register.htm
  1. <td class="altbg1">{lang password}:</td>
  2.         <td class="altbg2"><input type="password" name="password" size="25"
复制代码

后面加上
  1. onkeyup="javascript:SetPwdStrengthEx(document.forms[0],this.value);"
复制代码


3.查找templates\default\register.htm
  1. <tr>
  2.         <td class="altbg1">{lang password_confirm}:</td>
复制代码

前面加上
  1. <tr>
  2.     <script type="text/javascript" src="include/pswdplc.js"></script>
  3.                   <script type="text/javascript">
  4.             function DispPwdStrength(iN,sHL)
  5.            { 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");}}
  6.            </script>
  7.     <td class="altbg1">密码强度:</td>
  8.     <td class="altbg2"><table style="width: 255px; height: 20px;" cellpadding="0" cellspacing="0"><tbody><tr><td id="idSM1" style="background-color:#EBEBEB;border-right:solid 1px #BEBEBE;border-bottom:solid 1px #BEBEBE;" align="center" width="33%"><span style="font-size: 1px;"> </span><span id="idSMT1" style="display: none; color:#FF0000">弱</span></td><td id="idSM2" style="background-color:#EBEBEB;border-right:solid 1px #BEBEBE;border-bottom:solid 1px #BEBEBE;" align="center" width="34%"><span style="font-size: 1px;"> </span><span id="idSMT0" style="display: inline; font-weight: normal; color:#6633FF">未能评级</span><span id="idSMT2" style="display: none; color:#FF9900">中</span></td><td id="idSM3" style="background-color:#EBEBEB;border-right:solid 1px #BEBEBE;border-bottom:solid 1px #BEBEBE;"  align="center" width="33%"><span style="font-size: 1px;"> </span><span id="idSMT3" style="display: none; color:#339900">强</span></td></tr></tbody></table></td>
  9.    </tr>
复制代码


此密码强度乃彷MSN密码强度....希望有更强的彷google等等!





[ 本帖最后由 谨少爷 于 2005-12-12 19:37 编辑 ]

评分

1

查看全部评分

jimmyjimmyqqq 发表于 2005-12-12 19:37:45 | 显示全部楼层
強烈支持,加個分!
回复

使用道具 举报

yjflq2002 发表于 2005-12-12 19:44:27 | 显示全部楼层
有点意思,支持。
回复

使用道具 举报

yjflq2002 发表于 2005-12-12 19:49:39 | 显示全部楼层
装了下,就是在在输入密码的时候有点慢,而且密码在5位时好象没有判断。害得我以为这个插件无效

[ 本帖最后由 yjflq2002 于 2005-12-12 19:51 编辑 ]
回复

使用道具 举报

 楼主| 谨少爷 发表于 2005-12-12 19:58:34 | 显示全部楼层
原帖由 yjflq2002 于 2005-12-12 19:49 发表
装了下,就是在在输入密码的时候有点慢,而且密码在5位时好象没有判断。害得我以为这个插件无效


是6位开始判断!!

[ 本帖最后由 谨少爷 于 2005-12-12 20:01 编辑 ]
回复

使用道具 举报

 楼主| 谨少爷 发表于 2005-12-12 20:04:55 | 显示全部楼层
return (IsLongEnough(ClientSideWeakPassword.arguments[0], "6") ||
(!(IsLongEnough(ClientSideWeakPassword.arguments[0], "0"))));
}


pswdplc.js  里的 6字 改成 你认为几位开始判断就行了

不过我认为密码起嘛也是6位以上吧
回复

使用道具 举报

Trangerinfo 发表于 2005-12-12 20:09:00 | 显示全部楼层
顶上~!~占位~~支持~~
回复

使用道具 举报

hklcf 发表于 2005-12-12 20:25:40 | 显示全部楼层
很有用~支持
回复

使用道具 举报

haohao036 发表于 2005-12-12 20:36:36 | 显示全部楼层
等了好久。。就是这个。。
回复

使用道具 举报

风之夜 发表于 2005-12-12 22:05:48 | 显示全部楼层
这个很好呐~~~要了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-11-21 23:29 , Processed in 0.032529 second(s), 6 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表