OK
This commit is contained in:
commit
de840f111c
1 changed files with 15 additions and 0 deletions
15
password-generator.js
Normal file
15
password-generator.js
Normal 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());
|
Loading…
Reference in a new issue