Created
May 30, 2013 21:18
-
-
Save A-J-C/5681312 to your computer and use it in GitHub Desktop.
A CodePen by Alex C. Password timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: whitesmoke; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment