Skip to content

Instantly share code, notes, and snippets.

@paularmstrong
Created July 8, 2010 16:08
Show Gist options
  • Save paularmstrong/468228 to your computer and use it in GitHub Desktop.
Save paularmstrong/468228 to your computer and use it in GitHub Desktop.
function password_strength(password, username) {
var p = password
, u = username
;
if(
/^[a-z]*$/.test(p)
|| /^[A-Z]*$/.test(p)
|| /^[0-9]*$/.test(p)
) {
if(
(p.length < 8)
|| p == u
) {
return 'weak';
}
if(p.indexOf(u) != 1) {
return 'fair';
}
}
if(
!/^[a-zA-Z0-9]*$/.test(p)
) {
return 'strong';
}
if(
(/[a-z]*/.test(p) && /[A-Z]*/.test(p))
|| /^[a-zA-Z]*$/.test(p)
|| (!/^[a-zA-Z]*$/.test(p) && !/^[0-9]*$/.test(p))
) {
return 'medium';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment