-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
51 lines (51 loc) · 2.14 KB
/
javascript.js
File metadata and controls
51 lines (51 loc) · 2.14 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
var uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var lowercase = 'abcdefghijklmnopqrstuvwxyz';
var numbers = '0123456789';
var symbols = '!"#$%&\'()*+,-./:;<=>?@^[\\]^_`{|}~';
var userPass = "";
// Called by button "onclick" attributte. Generates a randomized password from a user generated list of characters.
function passGen() {
var passLen = document.getElementById("numUserChar").innerHTML;
// Generate user Character Set to use in password generation
var charsAllowed = includeCriteria();
// clear textarea of existing text(if any)
passClear();
// Generate the password
for (var i = 0; i < passLen; i++) {
userPass += charsAllowed.charAt(Math.floor(Math.random() * charsAllowed.length));
}
//prints Generated Password to Screen.
document.getElementById("genPassField").value = userPass;
};
// builds character set to use when randomizing password and validates that user has selected at least one input.
function includeCriteria() {
var charsRequested = "";
if (document.getElementById("upperCase").checked === false && document.getElementById("lowerCase").checked === false && document.getElementById("nums").checked === false && document.getElementById("specChar").checked === false) {
alert("You must choose at least one character set!");
} else {
if (document.getElementById("upperCase").checked) {
charsRequested += uppercase;
}
if (document.getElementById("lowerCase").checked) {
charsRequested += lowercase;
}
if (document.getElementById("nums").checked) {
charsRequested += numbers;
}
if (document.getElementById("specChar").checked) {
charsRequested += symbols;
}
return charsRequested;
}
};
// Clears Text Area. Called by passGen();
function passClear() {
userPass = "";
};
//slider code largely copied from https://www.w3schools.com/howto/howto_js_rangeslider.asp
var slider = document.getElementById("rangeSlide");
var output = document.getElementById("numUserChar");
output.innerHTML = slider.value;
slider.oninput = function () {
output.innerHTML = this.value;
}