-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (45 loc) · 1.55 KB
/
script.js
File metadata and controls
51 lines (45 loc) · 1.55 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
40
41
42
43
44
45
46
47
48
49
50
51
const upCheckBox = document.getElementById("uppercaseCheckbox");
const lowCheckBox = document.getElementById("lowercaseCheckbox");
const numCheckBox = document.getElementById("numbersCheckbox");
const specCheckBox = document.getElementById("specialCharsCheckbox");
const generateBtn = document.getElementById("generateButton");
const passwordDisplay = document.getElementById("passwordDisplay");
//Material tayaar
let UpperCaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let lowerCaseChars = "abcdefghijklmnopqrstuvwxyz";
let specialChars = "!@#$%^&*()_-=+";
let numbers = "1234567890";
generateBtn.addEventListener('click', function () {
let poolStr = '';
if (upCheckBox.checked) {
poolStr += UpperCaseChars
}
if (lowCheckBox.checked) {
poolStr += lowerCaseChars
}
if (numCheckBox.checked) {
poolStr += numbers
}
if (specCheckBox.checked) {
poolStr += specialChars
}
const passwordLen = document.getElementById("lengthInput").value;
if (passwordLen > 20) {
alert('Reached the max limit of length')
}
else {
let password = ''
// For Generating the Password from the poolStr Array
for (let i = 0; i < passwordLen; i++) {
const randomIndex = Math.floor(Math.random() * poolStr.length);
let randomChar = poolStr[randomIndex];
password += randomChar;
}
if (poolStr.length == 0) {
alert("Please Select Some Options");
}
else {
passwordDisplay.innerText = password;
}
}
})