How Do You Stop A Bar Chugging Off?

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

How Do You Stop A Bar Chugging Off?

chappill
Well I have this script that you can use to test your password strenght...But if you hold one key down for a while then lift it up the bar for password strength measuring pops out the box! Could someone look at my script and help please?
Thanks.
CODE
var commonPasswords = new Array('password', 'pass', '1234', '1246');

var numbers = "0123456789";
var lowercase = "abcdefghijklmnopqrstuvwxyz";
var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var punctuation = "!.@$£#*()%~<>{}[]";

function checkPassword(password) {

var combinations = 0;

if (contains(password, numbers) > 0) {
combinations += 10;
}

if (contains(password, lowercase) > 0) {
combinations += 10;
}

if (contains(password, uppercase) > 0) {
combinations += 10;
}

if (contains(password, punctuation) > 0) {
combinations += punctuation.length;
}


var totalCombinations = Math.pow(combinations, password.length);


if (isCommonPassword(password)) {
totalCombinations = 75000 // about the size of the dictionary
}


var timeInSeconds = (totalCombinations / 400) / 2;


var timeInDays = timeInSeconds / 86400


var lifetime = 365;


var percentage = timeInDays / lifetime;

var friendlyPercentage = cap(Math.round(percentage * 100), 100);
if (totalCombinations != 75000 && friendlyPercentage < (password.length * 3)) {
friendlyPercentage += password.length * 3;
}

var progressBar = document.getElementById("progressBar");
progressBar.style.width = friendlyPercentage + "%";

if (percentage > 1) {
// strong password
progressBar.style.backgroundColor = "#3bce08";
return;
}

if (percentage > 0.5) {
// reasonable password
progressBar.style.backgroundColor = "#ffd801";
return;
}

if (percentage > 0.10) {
// weak password
progressBar.style.backgroundColor = "orange";
return;
}

if (percentage <= 0.10) {
// weak password
progressBar.style.backgroundColor = "red";
return;
}


}

function cap(number, max) {
if (number > max) {
return max;
} else {
return number;
}
}

function isCommonPassword(password) {

for (i = 0; i < commonPasswords.length; i++) {
var commonPassword = commonPasswords[i];
if (password == commonPassword) {
return true;
}
}

return false;

}

function contains(password, validChars) {

count = 0;

for (i = 0; i < password.length; i++) {
var char = password.charAt(i);
if (validChars.indexOf(char) > -1) {
count++;
}
}

return count;
}


And the HTML I am using (because the 2 both tie):

CODE
<table>
<tr>
<td>Password:</td>
<td><input type="text" onKeyUp="checkPassword(this.value)"/></td>
<td>
<div style="border: 1px solid gray; width: 100px;">
<div id="progressBar"
style="font-size: 1px; height: 20px; width: 0px; border: 1px solid white;">
</div>
</div>
</td>
</tr>
</table>


Hope you can find and solve the problem from them 2!

 

 

 


Reply

rvalkass
Just make sure the percentage never goes above 100. If it does get above 100, just set it equal to 100.

CODE
var progressBar = document.getElementById("progressBar");
progressBar.style.width = friendlyPercentage + "%";


Becomes:

CODE
var progressBar = document.getElementById("progressBar");

if (friendlyPercentage > 100) {
friendlyPercentage = 100;
}
progressBar.style.width = friendlyPercentage + "%";

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : chugging


    Looking for stop, bar, chugging,

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for stop, bar, chugging,

*MORE FROM TRAP17.COM*
advertisement



How Do You Stop A Bar Chugging Off?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE