-
-
Save yckart/6384443 to your computer and use it in GitHub Desktop.
Password Strength
This file contains hidden or 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 (a) { | |
return ( | |
(a.length >= 8) + // length | |
/[a-z]/.test(a) + // lowercase | |
/[A-Z]/.test(a) + // uppercase | |
/\d/.test(a) + // number | |
/[^\w\s]|_/.test(a) // special | |
) * 20 | |
}; |
This file contains hidden or 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(a){return((a.length>=8)+/[a-z]/.test(a)+/[A-Z]/.test(a)+/\d/.test(a)+/[^\w\s]|_/.test(a))*20} |
This file contains hidden or 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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2013 Yannick Albert <http://yckart.com> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
This file contains hidden or 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
{ | |
"name": "passwordStrength", | |
"description": "Checks a string for its password strength.", | |
"keywords": [ | |
"password", | |
"strength", | |
"indicator", | |
"regexp", | |
"string" | |
] | |
} |
This file contains hidden or 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
<!DOCTYPE html> | |
<title>Foo</title> | |
<input id="input"> | |
<div id="ret"></div> | |
<script> | |
var strength = function(a){return((a.length>=8)+/[a-z]/.test(a)+/[A-Z]/.test(a)+/\d/.test(a)+/[^\w\s]|_/.test(a))*20}; | |
document.getElementById('input').onkeyup = function () { | |
document.getElementById('ret').innerHTML = strength(this.value); | |
}; | |
</script> |
Good point! I merged your 1st suggest. And ignored the 2nd one, eval
=== evil and looks too ugly to me... ;)
That was just to show how short it could be done. I wouldn't do something like that in real life.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
n / 5 * 100 = n * 20 and \d is shorter than [0-9]:
Even shorter if you use replace inside eval (ugly, but very short):