Skip to content

Instantly share code, notes, and snippets.

@A-J-C
Created May 30, 2013 21:18
Show Gist options
  • Save A-J-C/5681312 to your computer and use it in GitHub Desktop.
Save A-J-C/5681312 to your computer and use it in GitHub Desktop.
A CodePen by Alex C. Password timer
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css"/>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<input type="password"/>
<label id="password-label">Enter a Password</label>
</body>
</html>
function calculateComplexity(password, possibilities){
return Math.pow(possibilities, password.length);
}
var computerSpeed = 2900000000;
var totalPossibilities = 68;
function timeEstimate(password){
return formatTime(calculateComplexity(password, totalPossibilities) / computerSpeed);
}
$('document').ready(function() {
$('input:password').keyup(function() {
var input = $('input:password').val();
$('#password-label').html("Cracking your password would take " + timeEstimate(input));
});
});
var formatTime = function(time) {
var timeValue = " seconds";
if (time > 60){
time /= 60;
timeValue = " minutes";
if (time > 60){
time /= 60;
timeValue = " hours";
if (time > 24){
time /= 24;
timeValue = " days";
if (time > 7){
time /= 7;
timeValue = " weeks";
if (time > 52){
time /= 52;
timeValue = " years";
}
}
}
}
}
return time.toFixed(3) + timeValue;
};
body {
background-color: whitesmoke;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment