tracman-server/static/js/password.js

88 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-04-15 08:22:28 -06:00
'use strict';
2017-06-30 10:48:29 -06:00
/* global $ */
2017-04-15 08:22:28 -06:00
2017-06-30 10:48:29 -06:00
const zxcvbn = require('zxcvbn');
2017-04-15 08:22:28 -06:00
function checkMatch(){
$('#submit').prop('title',"You need to type your password again before you can save it. ");
// They match
if ( $('#p1').val() === $('#p2').val() ) {
$('#submit').prop('disabled',false).prop('title',"Click here to save your password. ");
}
// User has retyped, but they don't match yet
else if ($('#p2').val()!=='') {
2017-04-15 09:00:04 -06:00
$('#password-help').text("Those passwords don't match... ").css({'color':'#fb6e3d'});
2017-04-15 08:22:28 -06:00
$('#submit').prop('disabled',true).prop('title',"You need to type the same password twice before you can save it. ");
}
}
// On page load
$(function(){
// On typing password
$('.password').keyup(function(){
// Nothing entered
if ( $('#p1').val()==='' && $('#p2').val()==='' ){
$('#password-help').hide();
$('#submit').prop('disabled',true).prop('title',"You need to enter a password first. ");
}
// Only second password entered
else if ($('#p1').val()==='') {
2017-04-15 09:00:04 -06:00
$('#password-help').show().text("Those passwords don't match... ");
2017-04-15 08:22:28 -06:00
$('#submit').prop('disabled',true).prop('title',"You need to type the same password twice correctly before you can save it. ");
}
// At least first password entered
else {
$('#password-help').show();
// Check first password
2017-06-30 11:14:59 -06:00
var zxcvbnResult = zxcvbn($('#p1').val());
2017-04-15 08:22:28 -06:00
// Not good enough
2017-06-30 11:14:59 -06:00
if (zxcvbnResult.crack_times_seconds.online_no_throttling_10_per_second < 3600) { // Less than an hour
$('#password-help').text("That password is way too common or simple. You may not use it for Tracman and should not use it anywhere. ").css({'color':'#fb6e3d'});
2017-04-15 08:22:28 -06:00
$('#submit').prop('disabled',true).prop('title',"You need to come up with a better password. ");
}
2017-06-30 11:14:59 -06:00
else if (zxcvbnResult.crack_times_seconds.online_no_throttling_10_per_second < 86400) { // Less than a day
$('#password-help').text("That password is pretty bad. It could be cracked in "+zxcvbnResult.crack_times_display.online_no_throttling_10_per_second+". Try adding more words, numbers, or symbols. ").css({'color':'#fb6e3d'});
2017-04-15 08:48:56 -06:00
$('#submit').prop('disabled',true).prop('title',"You need to come up with a better password. ");
}
2017-06-30 11:14:59 -06:00
else if (zxcvbnResult.crack_times_seconds.online_no_throttling_10_per_second < 864000) { // Less than ten days
$('#password-help').text("That password isn't good enough. It could be cracked in "+zxcvbnResult.crack_times_display.online_no_throttling_10_per_second+". Try adding another word, number, or symbol. ").css({'color':'#fb6e3d'});
2017-04-15 08:22:28 -06:00
$('#submit').prop('disabled',true).prop('title',"You need to come up with a better password. ");
}
// Good enough
2017-06-30 11:14:59 -06:00
else if (zxcvbnResult.crack_times_seconds.online_no_throttling_10_per_second <= 2592000) { // Less than thirty days
$('#password-help').text("That password is good enough, but it could still be cracked in "+zxcvbnResult.crack_times_display.online_no_throttling_10_per_second+". ").css({'color':'#eee'});
2017-04-15 08:22:28 -06:00
checkMatch();
}
2017-06-30 11:14:59 -06:00
else if (zxcvbnResult.crack_times_seconds.online_no_throttling_10_per_second <= 1314000) { // Less than a year
$('#password-help').text("That password is good. It would take "+zxcvbnResult.crack_times_display.online_no_throttling_10_per_second+" to crack. ").css({'color':'#8ae137'});
2017-04-15 08:22:28 -06:00
checkMatch();
}
2017-06-30 11:14:59 -06:00
else { // Long ass time
$('#password-help').text("That password is great! It could take "+zxcvbnResult.crack_times_display.online_no_throttling_10_per_second+" to crack!").css({'color':'#8ae137'});
2017-04-15 08:53:12 -06:00
checkMatch();
}
2017-04-15 08:22:28 -06:00
}
});
// On checking 'show'
$('#show').click(function(){
if ($(this).is(':checked')) {
$('.password').attr('type','text');
} else {
$('.password').attr('type','password');
}
});
});