-
-
Save ireneyiu/840ba57b09ed6d71fc05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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