-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
191 lines (179 loc) · 5.81 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
var inputDisplay = document.getElementById("inputDisplay"); // Display input
var clipBoard = document.querySelector("#clipBoard"); // Weak Password Div
var copyInput = document.querySelector(".copy"); // Copy input
var copiedInput = document.querySelector(".copied"); // Copied input
var generatePassBtn = document.querySelector("#btn"); // Password Generator Button
// Demo Driver-JS
var demo = document.getElementById("demo");
const driver = window.driver.js.driver;
const driverObj = driver({
popoverClass: "driverjs-theme",
showProgress: true,
steps: [
{
element: ".display",
popover: {
title: "Display",
description: "Generated Passowrd Field",
},
},
{
element: ".p-show",
popover: {
title: "Show & Hide",
description: "You can hide your generated password by clicking this",
},
},
{
element: ".copy",
popover: {
title: "Copy to clipboard",
description: "Copy your generated password",
},
},
{
element: "#rangeBar",
popover: {
title: "Set range of password",
description: "Set the range of password by using scroll",
},
},
{
element: "#rangeValueDiv",
popover: {
title: "Character Length",
description: "You can see your password length here",
},
},
{
element: ".checkboxes",
popover: {
title: "Choose Character",
description: "Check box for choosing password characters",
},
},
{
element: "#btn",
popover: {
title: "Generate Password",
description: "Generate your password",
},
},
],
});
demo.addEventListener("click", () => {
driverObj.drive();
});
// Show & Hide Password
var showPassword = document.querySelector(".passIcon"); // Icon Container
var passShowIcon = document.querySelector(".p-show"); // Password Show icon
var passHideIcon = document.querySelector(".p-hidden"); // Password Hide icon
showPassword.addEventListener("click", () => {
if (inputDisplay.type === "password") {
inputDisplay.type = "text";
passHideIcon.style.display = "none";
passShowIcon.style.display = "block";
} else {
inputDisplay.type = "password";
passHideIcon.style.display = "block";
passShowIcon.style.display = "none";
}
});
// Getting & Showing Input Range
var rangeBar = document.querySelector("#rangeBar"); // Range Bar
var showRangebarValue = document.querySelector("#rangeDisplay"); // Show Range Bar Values
rangeBar.addEventListener("change", () => {
if (rangeBar.value < 10) {
// If count lessthen 10 the added a zero in numbers
showRangebarValue.innerHTML = 0 + rangeBar.value;
} else {
showRangebarValue.innerHTML = rangeBar.value;
}
});
// Copy ClipBoard
var empty = document.querySelector(".empty").style;
var emptyCheckBox = document.querySelector(".emptyCheckBox").style;
clipBoard.addEventListener("click", () => {
if (inputDisplay.value == "") {
empty.display = "block";
weakPass.style.display = "none";
strongPass.style.display = "none";
} else {
empty.display = "none";
inputDisplay.select();
document.execCommand("copy");
copiedInput.style.display = "block";
copyInput.style.display = "none";
}
});
var strongPass = document.querySelector(".strongPass"); // Strong Password Div
var weakPass = document.querySelector(".weakPass"); // Weak Password Div
// Password generation
function generatePass() {
empty.display = "none";
copiedInput.style.display = "none";
copyInput.style.display = "block";
var capitalLetters = document.querySelector("#capitalLetters"); // Capital Letters Check Box
var smallLetters = document.querySelector("#smallLetters"); // Small Letters Check Box
var numbers = document.querySelector("#numbers"); // Numbers Check Box
var specialCharacterCheckbox = document.querySelector("#specialCharacters"); // Special Characters Check Box
// Inside password characters
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
var specialCharacters = "!@#$%^&*(/)_<=]{,+}[|;.>:'?-";
var number0To9 = "0123456789";
// Checking If Check Box Checked
function getCheckedValues(checkboxes) {
var checkedValue = [];
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
checkedValue.push(checkboxes[i].value);
}
}
return checkedValue;
}
var capitalLettersChecked = getCheckedValues([capitalLetters]);
var smallLettersChecked = getCheckedValues([smallLetters]);
var numbersChecked = getCheckedValues([numbers]);
var specialCharactersChecked = getCheckedValues([specialCharacterCheckbox]);
var pass = []; // array for random number
// If checkbox checked the push there value in the above array
if (capitalLettersChecked.length > 0) {
pass.push(...uppercaseLetters);
}
if (smallLettersChecked.length > 0) {
pass.push(...lowercaseLetters);
}
if (numbersChecked.length > 0) {
pass.push(...number0To9);
}
if (specialCharactersChecked.length > 0) {
pass.push(...specialCharacters);
}
var generatePassword = "";
// Loop for generating password
for (var i = 0; i < rangeBar.value; i++) {
var getPass = pass[Math.floor(Math.random() * pass.length)];
generatePassword += getPass;
if (generatePassword === "undefined") {
generatePassword = "";
break;
}
}
// Generated password validation
if (
generatePassword.length >= 8 &&
capitalLettersChecked.length > 0 &&
smallLettersChecked.length > 0 &&
numbersChecked.length > 0 &&
specialCharactersChecked.length > 0
) {
weakPass.style.display = "none";
strongPass.style.display = "block";
} else {
weakPass.style.display = "block";
strongPass.style.display = "none";
}
// Display password
inputDisplay.value = generatePassword;
}