-
Notifications
You must be signed in to change notification settings - Fork 0
/
passwordGenerator.js
39 lines (30 loc) · 1.26 KB
/
passwordGenerator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const passwordLength = 10;
const includeLowercase = true;
const includeUppercase = true;
const includeNumbers = false;
const includeFigures = true;
function generatePassword(length, includeLowercase, includeUppercase, includeNumbers, includeFigures) {
const passwordIncludeLowercase = "abcdefghijklmnopurstyvwsqz";
const passwordIncludeUppercase = "abcdefghijklmnopurstyvwsqz".toUpperCase();
const passwordIncludeNumbers = "0123456789";
const passwordIncludeFigures = "!@^&*?_-";
let allowedChars = "";
let password = "";
allowedChars += includeLowercase ? passwordIncludeLowercase : "";
allowedChars += includeUppercase ? passwordIncludeUppercase : "";
allowedChars += includeNumbers ? passwordIncludeNumbers : "";
allowedChars += includeFigures ? passwordIncludeFigures : "";
if (length <= 0) {
return "reset the length"
}
if (allowedChars.length === 0) {
return "set the settings of your password"
}
for (let i = 0; i <= length; i++) {
const randomIndex = Math.floor(Math.random() * allowedChars.length);
password += allowedChars[randomIndex];
}
return password;
}
const password = generatePassword(passwordLength, includeLowercase, includeUppercase, includeNumbers, includeFigures);
console.log(`Your password ${password}`);