Check password safety with JavaScript while typing
You can show password strength to your visitors while typing before even submitting the page to the webserver. There are four character groups: letters, caps, numbers and symbols. A password which is longer than 7 characters and contains at least one character from each group is strong vz537gnjua. A password which is at least 8 character long and has all characters from one group is weak (but not very weak). A password which contains all characters from one group and at least 20 characters long is also strong. Rules are easy: longer is better, combined is the best.
Qw4567890123
a234567890123456
12345678901234567890
abcdefghijklmnoprstu
Demo:
Type your password!Strong Password Examples:
Qw#45678Qw4567890123
a234567890123456
12345678901234567890
abcdefghijklmnoprstu
Code:
<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 = '<span style="color: #0f0;">Your password is strong!</span>';
} else if( points >= 16 ) {
msg = '<span style="color: #00f;">Your password is medium!</span>';
} else if( points >= 12 ) {
msg = '<span style="color: #fa0;">Your password is weak!</span>';
} else {
msg = '<span style="color: #f00;">Your password is very weak!</span>';
}
password_info.innerHTML = msg ;
}
</script>
<input type="text" name="pwd" id="pwd" size="20" onkeyup="return check_password_safety(this.value);" />
<span id="password_info"><b>Type your password!</b></span>
Bookmark/Search this post with
Similar entries
- Change background color onmouseover with Javascript
- CSS Text effects for MSIE
- Redirect webpages with HTML, PHP, .htaccess, Java+Script, CGI-Perl, ASP.NET and ColdFusion
- Check password strength / safety with PHP and Regex
- Common HTML / Web colors
- Web2 style secure & flexible free php contact form with easy setup
- How to select a secure password for your online logins
- Regex (regular expression) password check with Java
- Howto protect admin.php / login.php with htaccess password
- Comparison of Mozilla Firefox 4 and Microsoft Internet Explorer 9
- Backup all MySQL databases automagicly with the PHP admin script
- Filezilla and plain-text clear, unsecure password storage
- Configure phpMyAdmin to login automagicly without prompted for username and password
- Test a webpage with IE5.5, IE6, IE7 and different javascript and css versions
- Pure CSS Mouseover Menu without Javascript
- Random tip / info-box with javascript array
- How to hide / encrypt CCK Email field with JS against spammer
- Web 2.0 Style two Side Background, Dark to Light Effect
- Web2 Style CSS Dynamic Menu with Arrows and Background-Images
- Repair all mysql databases-tables with PHP

Comments
Post new comment