Check password safety with JavaScript while typing

<script language="javascript">

function check_password_safety(pwd){

var msg = "";
var points = pwd.length;
var password_info = document.getElementById('password_info');

var has_letter = new RegExp("[a-z]");
var has_caps = new RegExp("[A-Z]");
var has_numbers = new RegExp("[0-9]");
var has_symbols = new RegExp("\\W");

if(has_letter.test(pwd)) { points += 4; }
if(has_caps.test(pwd)) { points += 4; }
if(has_numbers.test(pwd)) { points += 4; }
if(has_symbols.test(pwd)) { points += 4; }


if( points >= 24 ) {
msg = 'Your password is strong!';
} else if( points >= 16 ) {
msg = 'Your password is medium!';
} else if( points >= 12 ) {
msg = 'Your password is weak!';
} else {
msg = 'Your password is very weak!';
}

password_info.innerHTML = msg ;
}


</script>

<input type="text" name="pwd" id="pwd" size="20" onkeyup="return check_password_safety(this.value);" />

Type your password!

Comments

Popular posts from this blog

HTML5 video loop src change on end play function

Set limit wp_nav_menu

Calculate percentage of a specific element has been scrolled into visible on the screen