77 lines
1.5 KiB
JavaScript
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 += '!"%&/()=?.,+#-@*_<>';
|
|
}
|