-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
97 lines (74 loc) · 2.45 KB
/
script.js
File metadata and controls
97 lines (74 loc) · 2.45 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
// Assignment Code
var array = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
var array2 = "abcdefghijklmnopqrstuvwxyz".split("");
var num = "0123456789".split("");
var spec = "&%*@#$!".split("");
var options = "0123456789abcdefghijklmnopqrstuvwxyz".split("");
// var arrayLower = confirm("Would you like Lowercase letters?");
//var arrayUpper = confirm("Would you like Uppercase letters?");
//var numQues = confirm("Would you like numbers?");
// var specQues = confirm("Would you like special characters?");
//var passLength = prompt(
// "What's the length of the Password that you want? It has to be between 8 and 128 characters."
// );
// var newPass = confirm("Do You Need a New Password?");
// var newPass = (arrayLower = arrayUpper = numQues = specQues = true);
var generateBtn = document.querySelector("#generate");
// Write password to the #password input
function generatePassword() {
var randomPassword;
var options = [];
var characterArray = [];
var prompts = promptMe();
console.log(prompts);
if (prompts.hasLower) {
options = options.concat(array2);
}
if (prompts.hasUpper) {
options = options.concat(array);
}
if (prompts.hasNum) {
options = options.concat(num);
}
if (prompts.hasSpec) {
options = options.concat(spec);
}
for (var i = 0; i < prompts.passLength; i++) {
var randIndex = Math.floor(Math.random() * options.length);
var result = options[randIndex];
characterArray.push(result);
}
randomPassword = characterArray.join("");
console.log(options);
return randomPassword;
}
function writePassword() {
var password = generatePassword();
var passwordText = document.querySelector("#password");
passwordText.value = password;
}
// Add event listener to generate button
generateBtn.addEventListener("click", writePassword);
function promptMe() {
// alert(newPass);
// write a function or something that selects between 8 to 128 characters
var passLength = prompt(
"Between 8 and 128 characters, How long should the Password to be?"
);
if (passLength >= 8 && passLength <= 128) {
var hasLower = confirm("Would you like Lowercase letters?");
var hasUpper = confirm("Would you like Uppercase letters?");
var hasNum = confirm("Would you also like numbers?");
var hasSpec = confirm("Would you like special characters?");
} else {
return alert("Invalid Length");
}
var values = {
passLength,
hasLower,
hasUpper,
hasNum,
hasSpec,
};
return values;
}