-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
140 lines (126 loc) · 4.47 KB
/
Copy pathscript.js
File metadata and controls
140 lines (126 loc) · 4.47 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
// Assignment Code
var generateBtn = document.querySelector("#generate");
var passwordLength;
var confirmLower;
var confirmUpper;
var confirmNumber;
var confirmSpecial;
var userChoices;
var lowerCase = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
// Var To Upper Case ------------
var blankUpper = [];
var toUpper = function (x) {
return x.toUpperCase();
};
upperCase = lowerCase.map(toUpper);
//--------------------------------------
var numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var special = ["!", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", "\:", "\;", " < ", "=", " > ", " ? ", "@", "[", "\\", "]", " ^ ", "_", "`", "{", "|", "}", "~"];
// 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);
// Start Function
function generatePassword() {
// Ask four user Input
passwordLength = prompt("How many characters would you like your password? Choose between 8 and 128");
console.log("Password length " + passwordLength);
if(!passwordLength) {
alert("Required value");
} else if (passwordLength < 8 || passwordLength > 128) {
passwordLength = prompt("You must choose between 8 and 128");
console.log("Password length " + passwordLength);
} else {
confirmLower = confirm("Will this contain lower case letters?");
console.log("Lower case " + confirmLower);
confirmUpper = confirm("Will this contain upper case letters?");
console.log("Upper case " + confirmUpper);
confirmNumber = confirm("Will this contain numbers?");
console.log("Number " + confirmNumber);
confirmSpecial = confirm("Will this contain special characters?");
console.log("Special Character " + confirmSpecial);
};
// No answer then
if (!confirmLower && !confirmUpper && !confirmNumber && !confirmSpecial) {
userChoices = alert("You must choose a criteria");
// 4 true options
} else if (confirmLower && confirmUpper && confirmNumber && confirmSpecial) {
userChoices = lowerCase.concat(upperCase, numbers, special);
console.log(userChoices);
}
// 3 true options
else if (confirmLower && confirmUpper && confirmNumber) {
userChoices = lowerCase.concat(upperCase, numbers);
console.log(userChoices);
}
else if (confirmLower && confirmUpper && confirmSpecial) {
userChoices = lowerCase.concat(upperCase, special);
console.log(userChoices);
}
else if (confirmLower && confirmNumber && confirmSpecial) {
userChoices = lowerCase.concat(numbers, special);
console.log(userChoices);
}
else if (confirmUpper && confirmNumber && confirmSpecial) {
userChoices = upperCase.concat(numbers, special);
console.log(userChoices);
}
// 2 true options
else if (confirmLower && confirmUpper) {
userChoices = lowerCase.concat(upperCase);
console.log(userChoices);
}
else if (confirmLower && confirmNumber) {
userChoices = lowerCase.concat(numbers);
console.log(userChoices);
}
else if (confirmLower && confirmSpecial) {
userChoices = lowerCase.concat(special);
console.log(userChoices);
}
else if (confirmUpper && confirmNumber) {
userChoices = upperCase.concat(numbers);
console.log(userChoices);
}
else if (confirmUpper && confirmSpecial) {
userChoices = upperCase.concat(special);
console.log(userChoices);
}
else if (confirmNumber && confirmSpecial) {
userChoices = numbers.concat(special);
console.log(userChoices);
}
// 1 true option
else if (confirmLower) {
userChoices = lowerCase;
console.log(userChoices);
}
else if (confirmUpper) {
userChoices = blankUpper.concat(upperCase);
console.log(userChoices);
}
else if (confirmNumber) {
userChoices = numbers;
console.log(userChoices);
}
else if (confirmSpecial) {
userChoices = special;
console.log(userChoices);
};
// Empty variable for the password lenght
var passwordBlank = [];
// Loop for random selection
for (var i = 0; i < passwordLength; i++) {
var allChoices = userChoices[Math.floor(Math.random() * userChoices.length)];
passwordBlank.push(allChoices);
console.log(allChoices);
}
// Join and return the password
var password = passwordBlank.join("");
console.log("Your Pasword is: " + password);
return password;
}