-
Notifications
You must be signed in to change notification settings - Fork 829
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (34 loc) · 1.26 KB
/
script.js
File metadata and controls
39 lines (34 loc) · 1.26 KB
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
39
function generatePassword(length, includeLowercase, includeNumbers, includeSymbols, includeUppercase){
const lowercaseChars = "abscdefghijklopqrstuvwxyz";
const uppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const numberChars = "0123456789"
const symbolChars = "@._&";
let allowedChars = " ";
let password = "";
allowedChars += includeLowercase ? lowercaseChars: "";
allowedChars += includeUppercase ? uppercaseChars: "";
allowedChars += includeNumbers ? numberChars:"";
allowedChars += includeSymbols ? symbolChars:"";
console.log(allowedChars);
if(length <= 0){
return `(password length must be at least 1)`;
}
if(allowedChars.length === 0){
return `(At least 1 char needs to be selected)`
}
for(let i = 0; i<length; i++){
const randomIndex = Math.floor(Math.random() * allowedChars.length);
password += allowedChars[randomIndex];
}
return password;
}
const passwordLength = 12;
const includeLowercase = true;
const includeUppercase = true;
const includeNumbers = true;
const includeSymbols = true;
const password = generatePassword(passwordLength, includeLowercase,
includeNumbers,
includeUppercase,
includeSymbols);
console.log(`Generated Password:${password}`);