-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
226 lines (196 loc) · 8.98 KB
/
Copy pathscript.js
File metadata and controls
226 lines (196 loc) · 8.98 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Assignment Code
var generateBtn = document.querySelector("#generate");
function generatePassword() {
let password =''; //Initialize password variable as an empty string
// All character condition
let charAllCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={}[]|:;"<,>.?/'; //1st Condition
// Missing 1 type conditions
let charNoUpper = 'abcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()_-+={}[]|:;"<,>.?/';//2nd Condition
let charNoLower = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()_-+={}[]|:;"<,>.?/';//3rd Condition
let charNoNumeric = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~`!@#$%^&*()_-+={}[]|:;"<,>.?/';//4th Condition
let charNoSpecial = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';//5th Condition
// Missing 2 types conditions
let charNoNumericNoUpper = 'abcdefghijklmnopqrstuvwxyz~`!@#$%^&*()_-+={}[]|:;"<,>.?/';//6th Condition
let charNoNumericNoLower = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|:;"<,>.?/';//7th Condition
let charNoNumericNoSpecial = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';//8th Condition
let charNoSpecialNoUpper = 'abcdefghijklmnopqrstuvwxyz0123456789';//9th Condition
let charNoSpecialNoLower = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';//10th Condition
let charNoUpperNoLower = '0123456789~`!@#$%^&*()_-+={}[]|:;"<,>.?/';//11th Condition
// Missing 3 types conditions
let charOnlyLower = 'abcdefghijklmnopqrstuvwxyz';//12th Condition
let charOnlyUpper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';//13th Condition
let charOnlyNumeric = '0123456789';//14th Condition
let charOnlySpecial = '~`!@#$%^&*()_-+={}[]|:;"<,>.?/';//15th Condition
var passwordLength = prompt("How long do you want your password to be? Must be a value between 8 and 128."); //User prompt for password length
if (passwordLength < 8) {
alert('Password length too short. Please ensure length is between 8 and 128 characters.') //Condition to re-run password prompt if the length entered is less than 8
console.log("Password length input too short.")
return;
} else if (passwordLength > 128) {
alert('Password length too long. Please ensure length is between 8 and 128 characters.') //Condition to re-run password prompt if the length entered is greater than 128
console.log("Password length input too long.")
return;
} else {console.log("Successful password length set.") //Console verification of valid password length (8 to 128)
};
//Prompt asking user if uppercase characters are valid
var UpperCase = confirm("Allow uppercase letters? OK for YES, Cancel for NO");
console.log(`Uppercase Selection = ${UpperCase}.`)
//Prompt asking user if lowercase characters are valid
var LowerCase = confirm("Allow lowercase letters? OK for YES, Cancel for NO");
console.log(`Lowercase Selection = ${LowerCase}.`)
//Prompt asking user if numeric characters are valid
var Numeric = confirm("Allow numeric characters? OK for YES, Cancel for NO");
console.log(`Numeric Selection = ${Numeric}.`)
//Prompt asking user if special characters are valid
var Special = confirm("Allow special characters? OK for YES, Cancel for NO");
console.log(`Special Character Selection = ${Special}.`)
//1st Condition
if (UpperCase == true && LowerCase == true && Numeric == true && Special == true){
console.log("1st Condition Met - All Characters.")
let chars = charAllCharacters;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//2nd Condition
else if (UpperCase == false && LowerCase == true && Numeric == true && Special == true){
console.log("2nd Condition Met - No Uppercase.")
let chars = charNoUpper;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//3rd Condition
else if (UpperCase == true && LowerCase == false && Numeric == true && Special == true){
console.log("3rd Condition Met - No Lowercase.")
let chars = charNoLower;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//4th Condition
else if (UpperCase == true && LowerCase == true && Numeric == false && Special == true){
console.log("4th Condition Met - No Numeric.")
let chars = charNoNumeric;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//5th Condition
else if (UpperCase == true && LowerCase == true && Numeric == true && Special == false){
console.log("5th Condition Met - No Special.")
let chars = charNoSpecial;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//6th Condition
else if (UpperCase == false && LowerCase == true && Numeric == false && Special == true){
console.log("6th Condition Met - No Uppercase No Numeric.")
let chars = charNoNumericNoUpper;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//7th Condition
else if (UpperCase == true && LowerCase == false && Numeric == false && Special == true){
console.log("7th Condition Met - No Lowercase No Numeric.")
let chars = charNoNumericNoLower;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//8th Condition
else if (UpperCase == true && LowerCase == true && Numeric == false && Special == false){
console.log("8th Condition Met - No Numeric No Special.")
let chars = charNoNumericNoSpecial;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//9th Condition
else if (UpperCase == false && LowerCase == true && Numeric == true && Special == false){
console.log("9th Condition Met - No Uppercase No Special.")
let chars = charNoSpecialNoUpper;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//10th Condition
else if (UpperCase == true && LowerCase == false && Numeric == true && Special == false){
console.log("10th Condition Met - No Lowercase No Special.")
let chars = charNoSpecialNoLower;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//11th Condition
else if (UpperCase == false && LowerCase == false && Numeric == true && Special == true){
console.log("11th Condition Met - No Upeercase No Lowercase.")
let chars = charNoUpperNoLower;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//12th Condition
else if (UpperCase == false && LowerCase == true && Numeric == false && Special == false){
console.log("12th Condition Met - Only Lowercase.")
let chars = charOnlyLower;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//13th Condition
else if (UpperCase == true && LowerCase == false && Numeric == false && Special == false){
console.log("13th Condition Met - Only Uppercase.")
let chars = charOnlyUpper;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//14th Condition
else if (UpperCase == false && LowerCase == false && Numeric == true && Special == false){
console.log("14th Condition Met - Only Numeric.")
let chars = charOnlyNumeric;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//15th Condition
else if (UpperCase == false && LowerCase == false && Numeric == false && Special == true){
console.log("15th Condition Met - Only Special.")
let chars = charOnlySpecial;
for (let i = 0; i < passwordLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
//16th Condition
else {
password = "ERROR: No character types selected. Please regenerate your password and select at least (1) character type.";
console.log("16th Condition Met - No Character Types Selected.")
return password;
};
}
// Write password to the #password input
function writePassword() {
var password = generatePassword();
var passwordText = document.querySelector("#password");
passwordText.value = password;
}
// Add event listener to generate button
generateBtn.addEventListener("click", writePassword);