-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
184 lines (136 loc) · 5.16 KB
/
Copy pathscript.js
File metadata and controls
184 lines (136 loc) · 5.16 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
function generatePassword() {
/* Arrays to be used for random password */
let 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'];
let upperCase = ['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'];
let specialChar = ['!', '@', '#', '$', '%', '^', '&', '*', '?','+'];
let number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
let allChars = []
function chooseLength() {
var length = prompt("How long do you want your random password to be? (MIN: 8 characters MAX: 128 characters)", "");
length = parseInt(length);
if (length < 8) {
alert('Your password length is too short! Try again!');
chooseLength();
}
else if (length > 128) {
alert('Your password is too long! Try again!');
chooseLength();
}
else if (isNaN(length) === true) {
alert('You must enter a number! Try again!');
chooseLength();
}
else {
console.log(length);
return length
}
};
var passwordLength = chooseLength();
while(!lowerCheck && !upperCheck && !numCheck && !specialCheck){
alert("You must choose at least one criteria")
var lowerCheck = confirm("Do you want to include Lower case characters?")
var upperCheck = confirm("Do you want to include Upper case characters?")
var numCheck = confirm("Do you want to include Number characters?")
var specialCheck = confirm("Do you want to include Special characters?")
}
if(lowerCheck){
allChars = allChars.concat(lowerCase)
}
if(upperCheck){
allChars = allChars.concat(upperCase)
}
if(numCheck){
allChars = allChars.concat(number)
}
if(specialCheck){
allChars = allChars.concat(specialChar)
}
// /* Function to validate user input and include lowercase characters in randomized password if user answers Yes to prompt */
// function chooseLower() {
// var passwordLower = prompt("Do you want your random password to have lowercase letters?", "");
// passwordLower.toLowerCase();
// if (passwordLower === 'yes') {
// allChars.push(lowerCase);
// }
// else if (passwordLower === 'no') {
// }
// else {
// alert('You must enter "Yes" or "No"! Try again!');
// chooseLower();
// }
// };
// /* Function to validate user input and include uppercase characters in randomized password if user answers Yes to prompt */
// function chooseUpper() {
// var passwordUpper = prompt("Do you want your random password to have uppercase letters?", "");
// passwordUpper.toLowerCase();
// if (passwordUpper === 'yes') {
// allChars.push(upperCase);
// }
// else if (passwordUpper === 'no') {
// }
// else {
// alert('You must enter "Yes" or "No"! Try again!');
// chooseUpper();
// }
// };
// /* Function to validate user input and include special characters in randomized password if user answers Yes to prompt */
// function chooseSpecial() {
// var passwordSpecial = prompt("Do you want your random password to have special characters?", "");
// passwordSpecial.toLowerCase();
// if (passwordSpecial === 'yes') {
// allChars.push(specialChar);
// }
// else if (passwordSpecial === 'no') {
// }
// else {
// alert('You must enter "Yes" or "No"! Try again!');
// chooseSpecial();
// }
// };
// /* Function to validate user input and include numbers in randomized password if user answers Yes to prompt */
// function chooseNumber() {
// var passwordNumber = prompt("Do you want your random password to have numbers?", "");
// passwordNumber.toLowerCase();
// if (passwordNumber === 'yes') {
// allChars.push(number);
// }
// else if (passwordNumber === 'no') {
// }
// else {
// alert('You must enter "Yes" or "No"! Try again!');
// chooseNumber();
// }
// };
// chooseLower();
// chooseUpper();
// chooseSpecial();
// chooseNumber();
/* Function that randomizes elements from the specified array */
// function getRandom() {
// let index = allChars[Math.floor(Math.random() * allChars.length)];
// return index
// };
let password = ""
for(i=0; i<passwordLength; i++){
randomIndex = Math.floor(Math.random()* allChars.length);
randomCharacter = allChars[randomIndex]
password += randomCharacter
}
return password
// let password = [];
// /* runs the function the inputted number of times to get a random string of characters from the arrays */
// for (i = 0; i < passwordLength; i++) {
// password.push(getRandom());
// }
// return password.join("")
};
// Get references to the #generate element
var generateBtn = document.querySelector('#generate');
// Write password to the #password input
function writePassword() {
var randomPassword = generatePassword();
var passwordText = document.querySelector('#password');
return passwordText.value = randomPassword;
};
// Add event listener to generate button
generateBtn.addEventListener("click", writePassword);