This commit is contained in:
Rikuoh Tsujitani 2023-11-27 11:29:10 +09:00
commit de840f111c

15
password-generator.js Normal file
View file

@ -0,0 +1,15 @@
'use strict';
const length = 20;
const charset = 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + '0123456789' + '!@#$%^&*+?{}';
function passwordGenerator() {
let password = '';
for (let i = 0; i < length; i++) {
password += charset[Math.floor(Math.random() * charset.length)];
}
const includeAllTypes =
/[a-z]/.test(password) && /[A-Z]/.test(password) && /[0-9]/.test(password);
return includeAllTypes ? password : passwordGenerator();
}
console.log(passwordGenerator());