-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
163 lines (153 loc) · 3.3 KB
/
script.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
// Assignment Code
//Variables for the password generation
var generateBtn = document.querySelector("#generate");
var numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
var lowerCases = [
"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 upperCases = [
"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 special = [
"!",
"@",
"#",
"$",
"%",
"^",
"&",
"*",
"(",
")",
"+",
"-",
".",
"`",
"~",
"|",
"<",
">",
"=",
"-",
"_",
];
//User imput is exported from the object and compared to create a unique password and stored on the generatePassword Function
function generatePassword() {
console.log("Button Clicked!"); // Confirmation button was clicked
var options = collectUserInput();
console.log(options);
var allPossibleCharacters = [];
var password = "";
if (options.lowercase) {
allPossibleCharacters = allPossibleCharacters.concat(lowerCases);
}
if (options.upperCases) {
allPossibleCharacters = allPossibleCharacters.concat(upperCases);
}
if (options.special) {
allPossibleCharacters = allPossibleCharacters.concat(special);
}
if (options.numbers) {
allPossibleCharacters = allPossibleCharacters.concat(numbers);
}
for (var i = 0; i < options.length; i++) {
var arrayIndex = Math.floor(Math.random() * allPossibleCharacters.length);
var selectedArray = allPossibleCharacters[arrayIndex];
password = password + selectedArray
}
return password;
}
//Function collects user input and store in the object down.
function collectUserInput() {
var results = "";
var numberOfCharacters = window.prompt(
"How many characters would you like your password to contain?"
);
var characterQuantity = parseInt(numberOfCharacters);
if (isNaN(characterQuantity)) {
//if they put text instead of a number
alert("You need to enter a number.🤦 Try again!");
};
if (characterQuantity >= 8 && characterQuantity <= 128) {
var useLowercase = window.confirm("Click OK to confirm lowercase letter.");
var useUppercaser = window.confirm("Click OK to confirm Uppercase letter.");
var useNumbers = window.confirm("Click OK to confirm Numbers values");
var useSpecial = window.confirm("Click OK to confirm Special characters");
};
console.log("Questions answered");
//Inputs stored
return {
length: numberOfCharacters,
lowercase: useLowercase,
upperCases: useUppercaser,
special: useSpecial,
numbers: useNumbers,
};
}
// Write password to the #password input
function writePassword() {
var passwords = generatePassword();
var passwordText = document.querySelector("#password");
passwordText.value = passwords;
setTimeout(function () {
passwordText.value = "For your safety, your password 🔒 was delete";
setTimeout(function () {
passwordText.value = "Thanks for using the Password Generator!🤗 ";
setTimeout(function () {
passwordText.value = "Need another one?";
},1000)
},3500)
},8500)
}
// Add event listener to generate button
generateBtn.addEventListener("click", writePassword);