Re: Password Strength Meter
Re: Password Strength Meter
none yet.. but i found this code i dont know if this will work.. :)
pw_strenth.js
Code javascript:
// 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 = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}
// 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;
}
Re: Password Strength Meter
Ah yes, why bother writing our own code and learning when you can simply steal it from someone else?
Re: Password Strength Meter
im not stealing it, im trying to analyze how he/she codes it.. just using it as my reference.
Re: Password Strength Meter
You can achieve this by implementing a test for each of the 5 conditions.
Code java:
if password fails test 1
return false
if password fails test 2
return false
if password fails test 3
return false
if password fails test 4
return false
if password fails test 5
return false
return true // must have passed
Surely test 1 is simple. How do you test if a String has 7 characters? On the other hand, if you are keen you can use a regular expression.
Re: Password Strength Meter
Quote:
Originally Posted by
Junky
You can achieve this by implementing a test for each of the 5 conditions.
Code java:
if password fails test 1
return false
if password fails test 2
return false
if password fails test 3
return false
if password fails test 4
return false
if password fails test 5
return false
return true // must have passed
Surely test 1 is simple. How do you test if a String has 7 characters? On the other hand, if you are keen you can use a regular expression.
Adding to the Junky suggestion/comment, you can similarly test all five tests to achieve what you want to.
Hint is compare ASCII values.
Re: Password Strength Meter
Quote:
Originally Posted by Dr.Kernel
none yet.. but i found this code i dont know if this will work..
java != javascript. Do you wish to implement this in java, or javascript (these are java forums)