密码强度计
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了密码强度计相关的知识,希望对你有一定的参考价值。
PASSWORD STRENGTH METER (jquery) /** * Evaluate the strength of a user's password. * * Returns the estimated strength and the relevant output message. */ Drupal.evaluatePasswordStrength = function(value) { var strength = "", msg = "", translate = Drupal.settings.password; var hasLetters = value.match(/[a-zA-Z]+/); var hasNumbers = value.match(/[0-9]+/); var hasPunctuation = value.match(/[^a-zA-Z0-9]+/); var hasCasing = value.match(/[a-z]+.*[A-Z]+|[A-Z]+.*[a-z]+/); // Check if the password is blank. if (!value.length) { strength = ""; msg = ""; } // Check if length is less than 6 characters. else if (value.length < 6) { strength = "low"; msg = translate.tooShort; } // Check if password is the same as the username (convert both to lowercase). else if (value.toLowerCase() == translate.username.toLowerCase()) { strength = "low"; msg = translate.sameAsUsername; } // Check if it contains letters, numbers, punctuation, and upper/lower case. else if (hasLetters && hasNumbers && hasPunctuation && hasCasing) { strength = "high"; } // Password is not secure enough so construct the medium-strength message. else { // Extremely bad passwords still count as low. var count = (hasLetters ? 1 : 0) + (hasNumbers ? 1 : 0) + (hasPunctuation ? 1 : 0) + (hasCasing ? 1 : 0); strength = count > 1 ? "medium" : "low"; msg = []; if (!hasLetters || !hasCasing) { msg.push(translate.addLetters); } if (!hasNumbers) { msg.push(translate.addNumbers); } if (!hasPunctuation) { msg.push(translate.addPunctuation); } msg = translate.needsMoreVariation +"<ul><li>"+ msg.join("</li><li>") +"</li></ul>"; } return { strength: strength, message: msg }; };
以上是关于密码强度计的主要内容,如果未能解决你的问题,请参考以下文章