var aPasswordStrength = new Array(); aPasswordStrength[0] = new Array("Low", "PasswordTooShort"); aPasswordStrength[1] = new Array("Weak", "PasswordWeak"); aPasswordStrength[2] = new Array("Medium", "PasswordMedium"); aPasswordStrength[3] = new Array("Strong", "PasswordStrong"); function getPasswordStrength(sPassword, iPasswordLength) { var iScore = 0; //if password longer than 8 give 1 point if (sPassword.length >= iPasswordLength) { iScore += 1; } else { return 0; } // Yiran 2011-01-20 medium strength changes, true if any two of groups matched. //if password has both lower and uppercase characters and at least on number give 1 point if ((sPassword.match(/[a-z]/) && sPassword.match(/[A-Z]/)) || (sPassword.match(/[a-z]/) && sPassword.match(/\d+/)) || (sPassword.match(/[a-z]/) && sPassword.match(/\W/)) || (sPassword.match(/[A-Z]/) && sPassword.match(/\d+/)) || (sPassword.match(/[A-Z]/) && sPassword.match(/\W/)) || (sPassword.match(/\d+/) && sPassword.match(/\W/))) { iScore += 1; } //if password has at least one special caracther give 1 point if (sPassword.match(/[a-z]/) && sPassword.match(/[A-Z]/) && sPassword.match(/\d+/) && sPassword.match(/\W/)) { iScore += 1; } return iScore; } function setPasswordStrengthGUI(sTextFieldName, sPosBarFieldName, sNegBarFieldName, sPassword, iPasswordLength) { var iStrength = getPasswordStrength(sPassword, iPasswordLength) if (sPassword.length > 0) { document.getElementById(sTextFieldName).innerHTML = aPasswordStrength[iStrength][0]; } else { document.getElementById(sTextFieldName).innerHTML = ""; } document.getElementById(sTextFieldName).removeAttribute("class", 0); document.getElementById(sPosBarFieldName).removeAttribute("class", 0); document.getElementById(sNegBarFieldName).removeAttribute("class", 0); document.getElementById(sTextFieldName).setAttribute("class", aPasswordStrength[iStrength][1]); document.getElementById(sPosBarFieldName).setAttribute("class", aPasswordStrength[iStrength][1] + "Pos"); document.getElementById(sNegBarFieldName).setAttribute("class", aPasswordStrength[iStrength][1] + "Neg"); document.getElementById(sTextFieldName).className = aPasswordStrength[iStrength][1]; document.getElementById(sPosBarFieldName).className = aPasswordStrength[iStrength][1] + "Pos"; document.getElementById(sNegBarFieldName).className = aPasswordStrength[iStrength][1] + "Neg"; }