![]() |
Web Development »
Client side scripting »
General
Intermediate
License: The GNU General Public License (GPL)
Gmail Style Password Strength MeterBy Harmeet Singh BhamraGmail style password strength meter |
Javascript, CSS, HTML, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This is a simple password strength meter in Gmail style using CSS and JavaScript.
The basic idea before developing the script is to allow the user to evaluate the strength of the password which he is entering at the time of registration.
The zip file contains a *.html file which has JavaScript and CSS code in it. Just download it and run it.
Following is the JavaScript code which determines the strength of a password.
First 'if' checks whether or not the password length is greater than 4, if yes then 1 point value will be incremented by 1.These points will decide the CSS class to show as password strength graphically.
Second 'if' checks whether password contains lowercase and uppercase characters or not.
Third 'if' checks whether password contains at least 1 number or not.
Fourth 'if' checks whether password contains at least 1 special character or not.
Fifth 'if' checks whether password length is greater than 12 or not.
var points = 0; //---- password strength points.
//---- if password length is greater than 4, give 1 point.
if (password.length > 4) points++;
//---- if password has both lowercase and uppercase characters, give 1 point.
if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) points++;
//---- if password has at least one number, give 1 point.
if (password.match(/\d+/)) points++;
//---- if password has at least one special character, give 1 point.
if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) points++;
//---- if password length is greater than 12, give 1 point.
if (password.length > 12) points++;
Every time a user enters a character in the textbox, an onblur function executes and sends the value of password textbox to JavaScript function which evaluates the password and gives points to it.
A password_strength div will display colors according to the changed value of points variable.
A password_description div will show the text description of password using description (desc) array and points value.
Common guidelines for choosing good passwords are designed to make passwords less easily discovered by intelligent guessing:
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 7 Aug 2008 Editor: Deeksha Shenoy |
Copyright 2008 by Harmeet Singh Bhamra Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |