5,445,109 members and growing! (13,570 online)
Email Password   helpLost your password?
Web Development » Client side scripting » General     Intermediate License: The GNU General Public License (GPL)

Gmail style password strength meter

By Harmeet Singh Bhamra

Gmail style password strength meter
Javascript, CSS, HTML, Dev

Posted: 7 Aug 2008
Updated: 7 Aug 2008
Views: 2,377
Bookmarked: 17 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 3.15 Rating: 4.05 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 16.7%
3
2 votes, 33.3%
4
3 votes, 50.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

A simple password strength meter in Gmail style using CSS and JavaScript.

Background

The basic idea before developing the script is to allow user to evaluate the strength of the password which he is entering at the time of registration.

About the code

The zip file contains .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 password.

First 'if' checks the weather password length is greater then 4 or not, if yes then 1 point value will be incremented by 1.These points will decide the CSS class to show in as password strenght graphically.

Second 'if' checks weather password contains lowercase and uppercase characters or not.

Third 'if' checks weather password contains at least 1 number or not.

Fourth 'if' checks weather password contains at least 1 special character or not.

Fifth 'if' checks weather password strength is above 12 or not.

       var points = 0; //---- password strength points.

    //---- if password is bigger 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 is bigger than 12 ,  give 1 point.
    if (password.length > 12) points++;

How Code Works

Every time user enters a character in text box a onblur function executes and send the value of password textbox to javascript function which evaluates the password and give 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.

Guidelines for strong passwords

Common guidelines for choosing good passwords are designed to make passwords less easily discovered by intelligent guessing:

1) Include numbers, symbols, upper and lowercase letters in passwords.

2) Password length should be around 12 to 14 characters.

3) Avoid passwords based on repetition, dictionary words, letter or number sequences, usernames, or biographical information like names or dates.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPL)

About the Author

Harmeet Singh Bhamra



Occupation: Web Developer
Location: India India

Other popular Client side scripting articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralSmall typo...memberAndrew Rissing7:56 2 Sep '08  
GeneralA very good scriptmemberJaspreet Singh Bhatia2:59 8 Aug '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 7 Aug 2008
Editor:
Copyright 2008 by Harmeet Singh Bhamra
Everything else Copyright © CodeProject, 1999-2008
Web07 | Advertise on the Code Project