Click here to Skip to main content
6,293,171 members and growing! (11,540 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » Controls     Intermediate License: The Code Project Open License (CPOL)

Google Password Strength API

By Roger Chapman

An ASP.NET control for the Google Password Strength API.
Javascript, XML, CSS, HTML, C# 1.0, C# 2.0, Windows, .NET 1.1, .NET 2.0, ASP.NET, Ajax, VS.NET2003, VS2005, Dev, Design
Posted:18 Jun 2007
Updated:9 Nov 2007
Views:47,951
Bookmarked:62 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
16 votes for this article.
Popularity: 5.00 Rating: 4.15 out of 5
1 vote, 6.3%
1

2
2 votes, 12.5%
3
4 votes, 25.0%
4
9 votes, 56.3%
5

Screenshot - GooglePasswordStrength.gif

Introduction

Do you have an iGoogle Account? Well, if you are like the rest of the world that use the Internet, you will have, which also means that you have seen the very cool (and useful) "Password strength" control.

This control has a very intelligent API to determine if the password you entered is any good. It is "intelligent" in the fact that it does not just check that you have a password that is larger than six characters; e.g., a password "aaaaaaaaaaaa" will come out as "Weak", "my password" as "Good", and "grty3657DF?£hr4" as (yes you guessed it!) "Strong".

The big secret is this is actually a public API from Google, to which you can pass a password and it will return the password strength from 1 (least secure) to 4 (most secure). You can view it here.

And here is the "but", there is no interface for the control and it is not openly advertised by Google.

Background

When I found a use for such a control on a website I'm currently building, I first looked at the Microsoft AJAX Toolkit. At first, this worked great; however, I felt that the algorithm used was not as strong as the Google one, and I kept on getting JavaScript errors due to that control.

Bring on this control.

Using the code

The easiest way is to add a reference to the GooglePasswordStrength.dll, then add a section into the web.config:

<pages> 
    <controls> 
        <add tagPrefix="google" namespace="GooglePasswordStrength" 
             assembly="GooglePasswordStrength"/> 
    </controls> 
</pages>

Then, add the control to your page, and attach it to an asp:TextBox.

<table> 
    <tr> 
        <td><asp:TextBox ID="txtPassword" runat="server" /></td>
        <td><google:PasswordStrength ID="PS" 
                TargetControlID="txtPassword" 
                CssClass="password" runat="server" /></td>
    </tr> 
</table>

Points of interest

The control utilises AJAX, but does not require any third party AJAX library. However, if your application uses the Microsoft AJAX Library, the control invokes a Client Script Proxy that was written by Rick Strahl to handle all the client scripts.

Known issues

The XMLHttpRequest makes a call to the Google Password Strength API directly, so some browser settings may cause a "Permission Denied" error. This is because the XMLHttpRequest is making a call to a page outside of the local domain. In Microsoft Internet Explorer, you can change this setting under the Security Custom Level settings. Look for "Miscellaneous -> Access data sources across domains".

For a more robust, permanent solution, you will need to change the call to a page on the same domain and make a WebRequest to the Google API from there.

Update

  1. In the GooglePasswordStrength.Web Project, create a new WebForm called GetPassword.aspx.
  2. In GetPassword.aspx, delete all the lines except the @Page directive line.
  3. Open GetPassword.aspx.cs.
  4. In the Page_Load method, add the following code:
  5. string passwd = Request.QueryString["Passwd"];
    
    string GUrl = string.Format("https://www.google.com/" + 
                  "accounts/RatePassword?Passwd={0}", passwd);
    
    WebRequest webRequest = WebRequest.Create(GUrl);
    WebResponse webResponse = webRequest.GetResponse();
    StreamReader reader = new StreamReader(webResponse.GetResponseStream());
    
    Response.Clear();
    Response.Output.Write(reader.ReadToEnd());
    Response.End();
  6. Open PasswordStrength.js.
  7. On line 76, there is the xmlHttpObj.open method. Replace "https://www.google.com/accounts/RatePassword?Passwd=" with "GetPassword.aspx?Passwd=".
  8. Also, in the PasswordStrength.js file, replace all instances of "innerText" with "innerHTML" (I later found out that innerText is IE only).

Now, the XmlHttpRequestObject will make a call to a file on the same domain, and you will no longer get the security error.

History

  • November 2007 - Added a second demo, which uses the updated code above.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Roger Chapman


Member

Occupation: Software Developer (Senior)
Company: Storm ID Ltd.
Location: United Kingdom United Kingdom

Other popular Ajax and Atlas articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 38 (Total in Forum: 38) (Refresh)FirstPrevNext
GeneralProblem when the control is invisible on page load Pinmemberdc992:40 17 Apr '09  
GeneralProblem using Login and CreateUserWizard controls PinmemberMember 12582365:45 23 Jan '09  
GeneralCannot register the DLL PinmemberBhavna Vij4:35 6 Aug '08  
GeneralRe: Cannot register the DLL PinmemberRoger Chapman6:16 6 Aug '08  
QuestionOk, I am doing some things incorrectly obvioulsy... Pinmembertopdog5011:31 18 Jul '08  
AnswerRe: Ok, I am doing some things incorrectly obvioulsy... PinmemberRoger Chapman23:27 20 Jul '08  
QuestionChecking the strength Pinmemberwes lowe4:55 19 Jun '08  
AnswerRe: Checking the strength PinmemberRoger Chapman5:05 19 Jun '08  
QuestionRe: Checking the strength Pinmemberwes lowe5:42 19 Jun '08  
AnswerRe: Checking the strength PinmemberRoger Chapman5:55 19 Jun '08  
GeneralRe: Checking the strength Pinmemberwes lowe6:26 19 Jun '08  
GeneralHave a bug.. Pinmemberrodrigosor17:33 10 Jun '08  
AnswerRe: Have a bug.. PinmemberRoger Chapman23:13 10 Jun '08  
GeneralGoogle Password Strength API - demo2 not working PinmemberLeelavathy6:14 22 May '08  
AnswerRe: Google Password Strength API - demo2 not working PinmemberRoger Chapman6:25 22 May '08  
GeneralRe: Google Password Strength API - demo2 not working PinmemberLeelavathy5:49 23 May '08  
AnswerRe: Google Password Strength API - demo2 not working PinmemberRoger Chapman7:26 23 May '08  
Questioni could not run your control PinmemberEhsan Golkar3:20 28 Sep '07  
AnswerRe: i could not run your control PinmemberRoger Chapman3:26 28 Sep '07  
GeneralRe: i could not run your control PinmemberEhsan Golkar10:55 28 Sep '07  
GeneralRe: i could not run your control PinmemberRoger Chapman0:10 1 Oct '07  
AnswerRe: i could not run your control PinmemberEhsan Golkar20:40 1 Oct '07  
AnswerRe: i could not run your control PinmemberRoger Chapman23:36 1 Oct '07  
Generali m having problem Pinmembergoodonebond22:25 8 Aug '07  
AnswerRe: i m having problem PinmemberRoger Chapman23:10 8 Aug '07  

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

PermaLink | Privacy | Terms of Use
Last Updated: 9 Nov 2007
Editor: Smitha Vijayan
Copyright 2007 by Roger Chapman
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project