-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (42 loc) · 1.9 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const Generate = document.getElementById("generate");
const text = document.getElementById("Password");
let passwordLength
let includeLowercase
let includeUppercase
let includeNumbers
let includeSymbols
let allowedChars = ""
let generatedPassword = ""
const lowercaseChars = "abcdefghijklmnopqrstuvwxyz";
const uppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const numberChars = "0123456789";
const symbolChars = "!@#$%^&*()_+-=";
Generate.onclick = function(){
passwordLength = document.getElementById("Length").value;
includeLowercase = document.getElementById("lower");
includeUppercase = document.getElementById("upper");
includeNumbers = document.getElementById("numb");
includeSymbols = document.getElementById("symb");
function password(passwordLength, includeLowercase, includeUppercase, includeNumbers, includeSymbols){
allowedChars += includeLowercase.checked ? lowercaseChars : "";
allowedChars += includeUppercase.checked ? uppercaseChars : "";
allowedChars += includeNumbers.checked ? numberChars : "";
allowedChars += includeSymbols.checked ? symbolChars : "";
if(passwordLength <= 0 || passwordLength==null){
return `(Password length must be at least 1)`;
}
if(allowedChars.length === 0){
return `(At least 1 set of character needs to be selected)`;
}
for(let i = 0; i < passwordLength; i++){
const randomIndex = Math.floor(Math.random() * allowedChars.length);
generatedPassword += allowedChars[randomIndex];
}
return generatedPassword;
}
const Password = password(passwordLength, includeLowercase, includeUppercase, includeNumbers, includeSymbols)
text.textContent = Password
console.log(Password)
generatedPassword = ""
allowedChars = ""
}