JavaScript - i want to find password strength and dispaly

Asked By karthi keyan
27-Nov-08 01:03 AM
how to find the password strength dynamically.

try this  try this

27-Nov-08 01:05 AM
checkpwd: function(password) {
/*function to calculate "strength" of a password
* expects password, returns strength
*/
//calculate strength out of length
var strength = 0;
var length = password.length;
if (length > 16) {
strength = 18;
} else {
if (length > 8) {
strength = 12
} else {
if (length > 5) {
strength = 6;
} else {
if (length > 0) {
strength = 3;
} else {
return 0; //no password means no strength, :-)
}
}
}
}
//Now consider the letters
if (password.match(/[a-z]/i)) {
strength += 5; //at least one letter, 5 points
if (password.match(/[a-z][A-Z]|[A-Z][a-z]/)) {
strength += 2; //mixed-case adds 2 points
}
} //no letter, no points
//Now check for numbers
count = password.match(/[0-9]/g);
if (count) {
strength += 5; //at least one number, 5 points
if (count > 2) {
strength += 2; //three or more numbers, 2 extra points;
}
} //no number, no points
//Now check for special characters
count = password.match(/[!,@,#,$,%,^,*,?,_,~,-]/g)
if (count) {
strength += 5; //at least one special characters, 5 points
if (count > 1) {
strenth += 2; //two or more special characters, 2 extra points
}
} //no special characters, no points
return strength;
}

try this  try this

27-Nov-08 01:12 AM
// Password strength meter v1.0
// Matthew R. Miller - 2007
// www.codeandcoffee.com
// Based off of code from http://www.intelligent-web.co.uk

// Settings
// — Toggle to true or false, if you want to change what is checked in the password
var bCheckNumbers = true;
var bCheckUpperCase = true;
var bCheckLowerCase = true;
var bCheckPunctuation = true;
var nPasswordLifetime = 365;

// Check password
function checkPassword(strPassword)
{
// Reset combination count
nCombinations = 0;

// Check numbers
if (bCheckNumbers)
{
strCheck = “0123456789″;
if (doesContain(strPassword, strCheck) > 0)
{
nCombinations += strCheck.length;
}
}

// Check upper case
if (bCheckUpperCase)
{
strCheck = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;
if (doesContain(strPassword, strCheck) > 0)
{
nCombinations += strCheck.length;
}
}

// Check lower case
if (bCheckLowerCase)
{
strCheck = “abcdefghijklmnopqrstuvwxyz”;
if (doesContain(strPassword, strCheck) > 0)
{
nCombinations += strCheck.length;
}
}

// Check punctuation
if (bCheckPunctuation)
{
strCheck = “;:-_=+\|//?^&!.@$£#*()%~<>{}[]“;
if (doesContain(strPassword, strCheck) > 0)
{
nCombinations += strCheck.length;
}
}

// Calculate
// — 500 tries per second => minutes
var nDays = ((Math.pow(nCombinations, strPassword.length) / 500) / 2) / 86400;

// Number of days out of password lifetime setting
var nPerc = nDays / nPasswordLifetime;

return nPerc;
}

// Runs password through check and then updates GUI
function runPassword(strPassword, strFieldID)
{
// Check password
nPerc = checkPassword(strPassword);

// Get controls
var ctlBar = document.getElementById(strFieldID + “_bar”);
var ctlText = document.getElementById(strFieldID + “_text”);
if (!ctlBar || !ctlText)
return;

// Set new width
var nRound = Math.round(nPerc * 100);
if (nRound < (strPassword.length * 5))
{
nRound += strPassword.length * 5;
}
if (nRound > 100)
nRound = 100;
ctlBar.style.width = nRound + “%”;

// Color and text
if (nRound > 95)
{
strText = “Very Secure”;
strColor = “#3bce08″;
}
else if (nRound > 75)
{
strText = “Secure”;
strColor = “orange”;
}
else if (nRound > 50)
{
strText = “Mediocre”;
strColor = “#ffd801″;
}
else
{
strColor = “red”;
strText = “Insecure”;
}
ctlBar.style.backgroundColor = strColor;
ctlText.innerHTML = “” + strText + ““;
}

// Checks a string for a list of characters
function doesContain(strPassword, strCheck)
{
nCount = 0;

for (i = 0; i < strPassword.length; i++)
{
if (strCheck.indexOf(strPassword.charAt(i)) > -1)
{
nCount++;
}
}

return nCount;
}
[/ftf]

On the HTML side, I have setup a simple form to display the interaction the user will receive.

[ftf]


more info on

http://drupal.org/node/143026
http://www.drquincy.com/resources/tutorials/webclientside/passwordstrengthjavascript/
http://www.marketingtechblog.com/2007/08/27/javascript-password-strength/


Re :: Check Password Strength & Display using Javascript  Re :: Check Password Strength & Display using Javascript

27-Nov-08 01:12 AM

<script language="javascript">
function passwordChanged() {
var strength = document.getElementById(’strength’);
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
var pwd = document.getElementById("password");
if (pwd.value.length==0) {
strength.innerHTML = ‘Type Password’;
} else if (false == enoughRegex.test(pwd.value)) {
strength.innerHTML = ‘More Characters’;
} else if (strongRegex.test(pwd.value)) {
strength.innerHTML = ‘<span style="color:green">Strong!</span>’;
} else if (mediumRegex.test(pwd.value)) {
strength.innerHTML = ‘<span style="color:orange">Medium!</span>’;
} else { 
strength.innerHTML = ‘<span style="color:red">Weak!</span>’;
}
}
</script>
<input name="password" id="password" type="text" size="15" maxlength="20" onkeyup="return passwordChanged();" />
<span id="strength">Type Password</span>

 

Hope it helps.

Re :: Check Password Strength & Display using Javascript  Re :: Check Password Strength & Display using Javascript
27-Nov-08 01:14 AM

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 https://www.google.com/accounts/RatePassword?Passwd=replaceme.

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 http://ajax.asp.net/ajaxtoolkit/PasswordStrength/PasswordStrength.aspx. 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:

 Collapse
<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.

 Collapse
<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 thehttp://ajax.asp.net/, the control invokes a http://www.west-wind.com/WebLog/posts/9601.aspx 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 aWebRequest 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.  Collapse
    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 thatinnerText 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.

Complete Article & Download Source Code :: http://www.codeproject.com/KB/ajax/GooglePasswordStrength.aspx

Hope this helps.

re  re
27-Nov-08 01:55 AM
http://www.codeproject.com/KB/cs/PasswordStrengh.aspx
Create New Account
help