Skip to content

Instantly share code, notes, and snippets.

@ireneyiu
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ireneyiu/840ba57b09ed6d71fc05 to your computer and use it in GitHub Desktop.
Save ireneyiu/840ba57b09ed6d71fc05 to your computer and use it in GitHub Desktop.
$(function() {
$("input.zxcvbn").each(function() {
var $pw = $(this);
var $notify = $($pw.data("notify"));
var $confirm = $($pw.data("confirm"));
if ($notify[0]) {
$pw.keyup(assess);
$confirm.keyup(assess);
assess();
}
function assess() {
var pw = $pw.val();
if (pw.length < 6) {
$notify.html("Password must be at least 6 characters.");
} else if (this != $pw[0] && $confirm[0] &&
$confirm.val() && $confirm.val() != pw) {
$notify.html("Passwords don’t match.");
} else {
if (typeof zxcvbn !== "undefined") {
var z = zxcvbn(pw);
var text = "Password " + (z.score !== 0 ? "quality " : "") + "is ";
text += ["insecure","low","medium","good","fantastic"][z.score] + ".";
$notify.html(text);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment