Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/assets/js/password.js
2018-10-16 18:28:42 +02:00

77 lines
1.5 KiB
JavaScript

$('#passwordLength, .cmpoe').change(function() {
buildCatalog();
generatePassword();
});
$('form input').keydown(function(event){
if(event.keyCode === 13) {
event.preventDefault();
buildCatalog();
generatePassword();
}
});
$(function() {
buildCatalog();
generatePassword();
});
$('#copy').click(function() {
$('#password').select();
});
$('#password').click(function() {
$('#password').select();
});
$('#generate').click(function() {
generatePassword();
});
const comp = {
uppercase: true,
lowercase: true,
numbers: true,
symbols: true
};
let passwordLength = 15;
let catalog = '';
function generatePassword() {
let password = '';
for(let i = 0; i < passwordLength; i++) {
password += generateChar();
}
$('#password').text(password);
$('#history').append(`<li class="list-group-item">${password}</li>`);
}
function generateChar() {
const random = Math.floor(Math.random() * catalog.length);
return catalog[random];
}
function updateSettings() {
passwordLength = $('#passwordLength').val();
$('.cmpoe').each(function () {
comp[$(this).val()] = $(this).prop('checked');
});
}
function buildCatalog() {
updateSettings();
catalog = '';
if(comp.uppercase)
catalog += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if(comp.lowercase)
catalog += 'abcdefghijklmnopqrstuvwxyz';
if(comp.numbers)
catalog += '0123456789';
if(comp.symbols)
catalog += '!"%&/()=?.,+#-@*_<>';
}