1/* 2** Original File: pwd_meter.js 3** Created by: Jeff Todnem (http://www.todnem.com/) 4** Created on: 2007-08-14 5** Last modified: 2007-08-30 6** 7** License Information: 8** ------------------------------------------------------------------------- 9** Copyright (C) 2007 Jeff Todnem 10** 11** This program is free software; you can redistribute it and/or modify it 12** under the terms of the GNU General Public License as published by the 13** Free Software Foundation; either version 2 of the License, or (at your 14** option) any later version. 15** 16** This program is distributed in the hope that it will be useful, but 17** WITHOUT ANY WARRANTY; without even the implied warranty of 18** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19** General Public License for more details. 20** 21** You should have received a copy of the GNU General Public License along 22** with this program; if not, write to the Free Software Foundation, Inc., 23** 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24** 25** 26*/ 27 28function addLoadEvent(func) { 29 var oldonload = window.onload; 30 if (typeof window.onload != "function") { 31 window.onload = func; 32 } 33 else { 34 window.onload = function() { 35 if (oldonload) { 36 oldonload(); 37 } 38 func(); 39 }; 40 } 41} 42 43String.prototype.strReverse = function() { 44 var newstring = ""; 45 for (var s=0; s < this.length; s++) { 46 newstring = this.charAt(s) + newstring; 47 } 48 return newstring; 49 //strOrig = ' texttotrim '; 50 //strReversed = strOrig.revstring(); 51}; 52 53function chkPass(pwd) { 54 var oScorebar = document.getElementById("scorebar"); 55 var oScore = document.getElementById("score"); 56 var oComplexity = document.getElementById("complexity"); 57 var nScore = 0; 58 var nLength = 0; 59 var nAlphaUC = 0; 60 var nAlphaLC = 0; 61 var nNumber = 0; 62 var nSymbol = 0; 63 var nMidChar = 0; 64 var nRequirements = 0; 65 var nAlphasOnly = 0; 66 var nNumbersOnly = 0; 67 var nRepChar = 0; 68 var nConsecAlphaUC = 0; 69 var nConsecAlphaLC = 0; 70 var nConsecNumber = 0; 71 var nConsecSymbol = 0; 72 var nConsecCharType = 0; 73 var nSeqAlpha = 0; 74 var nSeqNumber = 0; 75 var nSeqChar = 0; 76 var nReqChar = 0; 77 var nReqCharType = 3; 78 var nMultLength = 4; 79 var nMultAlphaUC = 3; 80 var nMultAlphaLC = 3; 81 var nMultNumber = 4;
82 var nMultSymbol = 6; 83 var nMultMidChar = 2; 84 var nMultRequirements = 2; 85 var nMultRepChar = 1; 86 var nMultConsecAlphaUC = 2; 87 var nMultConsecAlphaLC = 2; 88 var nMultConsecNumber = 2; 89 var nMultConsecSymbol = 1; 90 var nMultConsecCharType = 0; 91 var nMultSeqAlpha = 3; 92 var nMultSeqNumber = 3; 93 var nTmpAlphaUC = ""; 94 var nTmpAlphaLC = ""; 95 var nTmpNumber = ""; 96 var nTmpSymbol = ""; 97 var sAlphaUC = " 0"; 98 var sAlphaLC = " 0"; 99 var sNumber = " 0"; 100 var sSymbol = " 0"; 101 var sMidChar = " 0"; 102 var sRequirements = " 0"; 103 var sAlphasOnly = " 0"; 104 var sNumbersOnly = " 0"; 105 var sRepChar = " 0"; 106 var sConsecAlphaUC = " 0"; 107 var sConsecAlphaLC = " 0"; 108 var sConsecNumber = " 0"; 109 var sSeqAlpha = " 0"; 110 var sSeqNumber = " 0"; 111 var sAlphas = "abcdefghijklmnopqrstuvwxyz"; 112 var sNumerics = "01234567890"; 113 var sComplexity = "Too Short"; 114 var sStandards = "Below"; 115 var nMinPwdLen = 8; 116 if (document.all) { var nd = 0; } else { var nd = 1; } 117 if (pwd) { 118 nScore = parseInt(pwd.length * nMultLength); 119 nLength = pwd.length; 120 var arrPwd = pwd.replace (/\s+/g,"").split(/\s*/); 121 var arrPwdLen = arrPwd.length; 122 123 /* Loop through password to check for Symbol, Numeric, Lowercase and Uppercase pattern matches */ 124 for (var a=0; a < arrPwdLen; a++) { 125 if (arrPwd[a].match(new RegExp(/[A-Z]/g))) { 126 if (nTmpAlphaUC !== "") { if ((nTmpAlphaUC + 1) == a) { nConsecAlphaUC++; nConsecCharType++; } } 127 nTmpAlphaUC = a; 128 nAlphaUC++; 129 } 130 else if (arrPwd[a].match(new RegExp(/[a-z]/g))) { 131 if (nTmpAlphaLC !== "") { if ((nTmpAlphaLC + 1) == a) { nConsecAlphaLC++; nConsecCharType++; } } 132 nTmpAlphaLC = a; 133 nAlphaLC++; 134 } 135 else if (arrPwd[a].match(new RegExp(/[0-9]/g))) { 136 if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; } 137 if (nTmpNumber !== "") { if ((nTmpNumber + 1) == a) { nConsecNumber++; nConsecCharType++; } } 138 nTmpNumber = a; 139 nNumber++; 140 } 141 else if (arrPwd[a].match(new RegExp(/[^a-zA-Z0-9_]/g))) { 142 if (a > 0 && a < (arrPwdLen - 1)) { nMidChar++; } 143 if (nTmpSymbol !== "") { if ((nTmpSymbol + 1) == a) { nConsecSymbol++; nConsecCharType++; } } 144 nTmpSymbol = a; 145 nSymbol++; 146 } 147 /* Internal loop through password to check for repeated characters */ 148 for (var b=0; b < arrPwdLen; b++) { 149 if (arrPwd[a].toLowerCase() == arrPwd[b].toLowerCase() && a != b) { nRepChar++; } 150 } 151 } 152 153 /* Check for sequential alpha string patterns (forward and reverse) */ 154 for (var s=0; s < 23; s++) { 155 var sFwd = sAlphas.substring(s,parseInt(s+3)); 156 var sRev = sFwd.strReverse(); 157 if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqAlpha++; nSeqChar++;} 158 } 159 160 /* Check for sequential numeric string patterns (forward and reverse) */ 161 for (var s=0; s < 8; s++) { 162 var sFwd = sNumerics.substring(s,parseInt(s+3)); 163 var sRev = sFwd.strReverse(); 164 if (pwd.toLowerCase().indexOf(sFwd) != -1 || pwd.toLowerCase().indexOf(sRev) != -1) { nSeqNumber++; nSeqChar++;} 165 } 166 167 /* Modify overall score value based on usage vs requirements */ 168 169 /* General point assignment */ 170 document.getElementById("nLengthBonus").innerHTML = "+ " + nScore; 171 if (nAlphaUC > 0 && nAlphaUC < nLength) { 172 nScore = parseInt(nScore + ((nLength - nAlphaUC) * 2)); 173 sAlphaUC = "+ " + parseInt((nLength - nAlphaUC) * 2); 174 } 175 if (nAlphaLC > 0 && nAlphaLC < nLength) { 176 nScore = parseInt(nScore + ((nLength - nAlphaLC) * 2)); 177 sAlphaLC = "+ " + parseInt((nLength - nAlphaLC) * 2); 178 } 179 if (nNumber > 0 && nNumber < nLength) { 180 nScore = parseInt(nScore + (nNumber * nMultNumber)); 181 sNumber = "+ " + parseInt(nNumber * nMultNumber); 182 } 183 if (nSymbol > 0) { 184 nScore = parseInt(nScore + (nSymbol * nMultSymbol)); 185 sSymbol = "+ " + parseInt(nSymbol * nMultSymbol); 186 } 187 if (nMidChar > 0) { 188 nScore = parseInt(nScore + (nMidChar * nMultMidChar));
189 sMidChar = "+ " + parseInt(nMidChar * nMultMidChar); 190 } 191 document.getElementById("nAlphaUCBonus").innerHTML = sAlphaUC; 192 document.getElementById("nAlphaLCBonus").innerHTML = sAlphaLC; 193 document.getElementById("nNumberBonus").innerHTML = sNumber; 194 document.getElementById("nSymbolBonus").innerHTML = sSymbol; 195 document.getElementById("nMidCharBonus").innerHTML = sMidChar; 196 197 /* Point deductions for poor practices */ 198 if ((nAlphaLC > 0 || nAlphaUC > 0) && nSymbol === 0 && nNumber === 0) { // Only Letters 199 nScore = parseInt(nScore - nLength); 200 nAlphasOnly = nLength; 201 sAlphasOnly = "- " + nLength; 202 } 203 if (nAlphaLC === 0 && nAlphaUC === 0 && nSymbol === 0 && nNumber > 0) { // Only Numbers 204 nScore = parseInt(nScore - nLength); 205 nNumbersOnly = nLength; 206 sNumbersOnly = "- " + nLength; 207 } 208 if (nRepChar > 0) { // Same character exists more than once 209 nScore = parseInt(nScore - (nRepChar * nRepChar)); 210 sRepChar = "- " + nRepChar; 211 } 212 if (nConsecAlphaUC > 0) { // Consecutive Uppercase Letters exist 213 nScore = parseInt(nScore - (nConsecAlphaUC * nMultConsecAlphaUC)); 214 sConsecAlphaUC = "- " + parseInt(nConsecAlphaUC * nMultConsecAlphaUC); 215 } 216 if (nConsecAlphaLC > 0) { // Consecutive Lowercase Letters exist 217 nScore = parseInt(nScore - (nConsecAlphaLC * nMultConsecAlphaLC)); 218 sConsecAlphaLC = "- " + parseInt(nConsecAlphaLC * nMultConsecAlphaLC); 219 } 220 if (nConsecNumber > 0) { // Consecutive Numbers exist 221 nScore = parseInt(nScore - (nConsecNumber * nMultConsecNumber)); 222 sConsecNumber = "- " + parseInt(nConsecNumber * nMultConsecNumber); 223 } 224 if (nSeqAlpha > 0) { // Sequential alpha strings exist (3 characters or more) 225 nScore = parseInt(nScore - (nSeqAlpha * nMultSeqAlpha)); 226 sSeqAlpha = "- " + parseInt(nSeqAlpha * nMultSeqAlpha); 227 } 228 if (nSeqNumber > 0) { // Sequential numeric strings exist (3 characters or more) 229 nScore = parseInt(nScore - (nSeqNumber * nMultSeqNumber)); 230 sSeqNumber = "- " + parseInt(nSeqNumber * nMultSeqNumber); 231 } 232 document.getElementById("nAlphasOnlyBonus").innerHTML = sAlphasOnly; 233 document.getElementById("nNumbersOnlyBonus").innerHTML = sNumbersOnly; 234 document.getElementById("nRepCharBonus").innerHTML = sRepChar; 235 document.getElementById("nConsecAlphaUCBonus").innerHTML = sConsecAlphaUC; 236 document.getElementById("nConsecAlphaLCBonus").innerHTML = sConsecAlphaLC; 237 document.getElementById("nConsecNumberBonus").innerHTML = sConsecNumber;
238 document.getElementById("nSeqAlphaBonus").innerHTML = sSeqAlpha; 239 document.getElementById("nSeqNumberBonus").innerHTML = sSeqNumber; 240 241 /* Determine if mandatory requirements have been met and set image indicators accordingly */ 242 var arrChars = [nLength,nAlphaUC,nAlphaLC,nNumber,nSymbol]; 243 var arrCharsIds = ["nLength","nAlphaUC","nAlphaLC","nNumber","nSymbol"]; 244 var arrCharsLen = arrChars.length; 245 for (var c=0; c < arrCharsLen; c++) { 246 var oImg = document.getElementById('div_' + arrCharsIds[c]); 247 var oBonus = document.getElementById(arrCharsIds[c] + 'Bonus'); 248 document.getElementById(arrCharsIds[c]).innerHTML = arrChars[c]; 249 if (arrCharsIds[c] == "nLength") { var minVal = parseInt(nMinPwdLen - 1); } else { var minVal = 0; } 250 if (arrChars[c] == parseInt(minVal + 1)) { nReqChar++; oImg.className = "pass"; oBonus.parentNode.className = "pass"; } 251 else if (arrChars[c] > parseInt(minVal + 1)) { nReqChar++; oImg.className = "exceed"; oBonus.parentNode.className = "exceed"; } 252 else { oImg.className = "fail"; oBonus.parentNode.className = "fail"; } 253 } 254 nRequirements = nReqChar; 255 if (pwd.length >= nMinPwdLen) { var nMinReqChars = 3; } else { var nMinReqChars = 4; } 256 if (nRequirements > nMinReqChars) { // One or more required characters exist 257 nScore = parseInt(nScore + (nRequirements * 2)); 258 sRequirements = "+ " + parseInt(nRequirements * 2); 259 } 260 document.getElementById("nRequirementsBonus").innerHTML = sRequirements; 261 262 /* Determine if additional bonuses need to be applied and set image indicators accordingly */ 263 var arrChars = [nMidChar,nRequirements]; 264 var arrCharsIds = ["nMidChar","nRequirements"]; 265 var arrCharsLen = arrChars.length; 266 for (var c=0; c < arrCharsLen; c++) { 267 var oImg = document.getElementById('div_' + arrCharsIds[c]); 268 var oBonus = document.getElementById(arrCharsIds[c] + 'Bonus'); 269 document.getElementById(arrCharsIds[c]).innerHTML = arrChars[c]; 270 if (arrCharsIds[c] == "nRequirements") { var minVal = nMinReqChars; } else { var minVal = 0; } 271 if (arrChars[c] == parseInt(minVal + 1)) { oImg.className = "pass"; oBonus.parentNode.className = "pass"; } 272 else if (arrChars[c] > parseInt(minVal + 1)) { oImg.className = "exceed"; oBonus.parentNode.className = "exceed"; } 273 else { oImg.className = "fail"; oBonus.parentNode.className = "fail"; } 274 } 275 276 /* Determine if suggested requirements have been met and set image indicators accordingly */ 277 var arrChars = [nAlphasOnly,nNumbersOnly,nRepChar,nConsecAlphaUC,nConsecAlphaLC,nConsecNumber,nSeqAlpha,nSeqNumber]; 278 var arrCharsIds = ["nAlphasOnly","nNumbersOnly","nRepChar","nConsecAlphaUC","nConsecAlphaLC","nConsecNumber","nSeqAlpha","nSeqNumber"]; 279 var arrCharsLen = arrChars.length; 280 for (var c=0; c < arrCharsLen; c++) { 281 var oImg = document.getElementById('div_' + arrCharsIds[c]); 282 var oBonus = document.getElementById(arrCharsIds[c] + 'Bonus'); 283 document.getElementById(arrCharsIds[c]).innerHTML = arrChars[c]; 284 if (arrChars[c] > 0) { oImg.className = "warn"; oBonus.parentNode.className = "warn"; } 285 else { oImg.className = "pass"; oBonus.parentNode.className = "pass"; } 286 } 287 288 /* Determine complexity based on overall score */ 289 if (nScore > 100) { nScore = 100; } else if (nScore < 0) { nScore = 0; } 290 if (nScore >= 0 && nScore < 20) { sComplexity = "Very Weak"; } 291 else if (nScore >= 20 && nScore < 40) { sComplexity = "Weak"; } 292 else if (nScore >= 40 && nScore < 60) { sComplexity = "Good"; } 293 else if (nScore >= 60 && nScore < 80) { sComplexity = "Strong"; } 294 else if (nScore >= 80 && nScore <= 100) { sComplexity = "Very Strong"; } 295 296 /* Display updated score criteria to client */ 297 oScorebar.style.backgroundPosition = "-" + parseInt(nScore * 4) + "px"; 298 oScore.innerHTML = nScore + "%"; 299 oComplexity.innerHTML = sComplexity; 300 } 301 else { 302 /* Display default score criteria to client */ 303 initPwdChk(); 304 oScore.innerHTML = nScore + "%"; 305 oComplexity.innerHTML = sComplexity; 306 } 307} 308 309function togPwdMask() { 310 var oPwd = document.getElementById("passwordPwd"); 311 var oTxt = document.getElementById("passwordTxt"); 312 var oMask = document.getElementById("mask"); 313 if (oMask.checked) { 314 oPwd.value = oTxt.value; 315 oPwd.className = ""; 316 oTxt.className = "hide"; 317 } 318 else { 319 oTxt.value = oPwd.value; 320 oPwd.className = "hide"; 321 oTxt.className = ""; 322 } 323} 324 325function initPwdChk(restart) { 326 /* Reset all form values to their default */ 327 document.getElementById("nLength").innerHTML = "0"; 328 document.getElementById("nAlphaUC").innerHTML = "0"; 329 document.getElementById("nAlphaLC").innerHTML = "0"; 330 document.getElementById("nNumber").innerHTML = "0"; 331 document.getElementById("nSymbol").innerHTML = "0"; 332 document.getElementById("nMidChar").innerHTML = "0"; 333 document.getElementById("nRequirements").innerHTML = "0"; 334 document.getElementById("nAlphasOnly").innerHTML = "0"; 335 document.getElementById("nNumbersOnly").innerHTML = "0"; 336 document.getElementById("nRepChar").innerHTML = "0"; 337 document.getElementById("nConsecAlphaUC").innerHTML = "0"; 338 document.getElementById("nConsecAlphaLC").innerHTML = "0"; 339 document.getElementById("nConsecNumber").innerHTML = "0";
340 document.getElementById("nSeqAlpha").innerHTML = "0"; 341 document.getElementById("nSeqNumber").innerHTML = "0"; 342 document.getElementById("nLengthBonus").innerHTML = " 0"; 343 document.getElementById("nAlphaUCBonus").innerHTML = " 0"; 344 document.getElementById("nAlphaLCBonus").innerHTML = " 0"; 345 document.getElementById("nNumberBonus").innerHTML = " 0"; 346 document.getElementById("nSymbolBonus").innerHTML = " 0"; 347 document.getElementById("nMidCharBonus").innerHTML = " 0"; 348 document.getElementById("nRequirementsBonus").innerHTML = " 0"; 349 document.getElementById("nAlphasOnlyBonus").innerHTML = " 0"; 350 document.getElementById("nNumbersOnlyBonus").innerHTML = " 0"; 351 document.getElementById("nRepCharBonus").innerHTML = " 0"; 352 document.getElementById("nConsecAlphaUCBonus").innerHTML = " 0"; 353 document.getElementById("nConsecAlphaLCBonus").innerHTML = " 0"; 354 document.getElementById("nConsecNumberBonus").innerHTML = " 0";
355 document.getElementById("nSeqAlphaBonus").innerHTML = " 0"; 356 document.getElementById("nSeqNumberBonus").innerHTML = " 0"; 357 document.getElementById("nLengthBonus").parentNode.className = "fail"; 358 document.getElementById("nAlphaUCBonus").parentNode.className = "fail"; 359 document.getElementById("nAlphaLCBonus").parentNode.className = "fail"; 360 document.getElementById("nNumberBonus").parentNode.className = "fail"; 361 document.getElementById("nSymbolBonus").parentNode.className = "fail"; 362 document.getElementById("nMidCharBonus").parentNode.className = "fail"; 363 document.getElementById("nRequirementsBonus").parentNode.className = "fail"; 364 document.getElementById("nAlphasOnlyBonus").parentNode.className = "pass"; 365 document.getElementById("nNumbersOnlyBonus").parentNode.className = "pass"; 366 document.getElementById("nRepCharBonus").parentNode.className = "pass"; 367 document.getElementById("nConsecAlphaUCBonus").parentNode.className = "pass"; 368 document.getElementById("nConsecAlphaLCBonus").parentNode.className = "pass"; 369 document.getElementById("nConsecNumberBonus").parentNode.className = "pass";
370 document.getElementById("nSeqAlphaBonus").parentNode.className = "pass"; 371 document.getElementById("nSeqNumberBonus").parentNode.className = "pass"; 372 document.getElementById("div_nLength").className = "fail"; 373 document.getElementById("div_nAlphaUC").className = "fail"; 374 document.getElementById("div_nAlphaLC").className = "fail"; 375 document.getElementById("div_nNumber").className = "fail"; 376 document.getElementById("div_nSymbol").className = "fail"; 377 document.getElementById("div_nMidChar").className = "fail"; 378 document.getElementById("div_nRequirements").className = "fail"; 379 document.getElementById("div_nAlphasOnly").className = "pass"; 380 document.getElementById("div_nNumbersOnly").className = "pass"; 381 document.getElementById("div_nRepChar").className = "pass"; 382 document.getElementById("div_nConsecAlphaUC").className = "pass"; 383 document.getElementById("div_nConsecAlphaLC").className = "pass"; 384 document.getElementById("div_nConsecNumber").className = "pass"; 385 document.getElementById("div_nSeqAlpha").className = "pass"; 386 document.getElementById("div_nSeqNumber").className = "pass"; 387 document.getElementById("passwordPwd").value = ""; 388 document.getElementById("passwordTxt").value = ""; 389 document.getElementById("scorebar").style.backgroundPosition = "0"; 390 if (restart) { 391 document.getElementById("passwordPwd").className = ""; 392 document.getElementById("passwordTxt").className = "hide"; 393 document.getElementById("mask").checked = true; 394 } 395} 396 397addLoadEvent(function() { initPwdChk(1); }); 398
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.