-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (60 loc) · 2.43 KB
/
Copy pathscript.js
File metadata and controls
72 lines (60 loc) · 2.43 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
const passwordLength = document.getElementById("password-length");
const passwordSlider = document.getElementById("password-slider");
const lowercaseBox = document.getElementById("lowercase-letters");
const uppercaseBox = document.getElementById("uppercase-letters");
const numbers = document.getElementById("numbers");
const specialChar = document.getElementById("special");
const unambiguous = document.getElementById("unambiguous");
const generateButton = document.getElementById("generate-button");
const printOutput = document.getElementById("output");
const copyButton = document.getElementById("copy-button");
//show the default slider value when the page loads
passwordLength.innerHTML = passwordSlider.value;
//show the slider value when it gets moved
passwordSlider.oninput = () => passwordLength.innerHTML = passwordSlider.value;
let copyPassword = () => {
//using clipboard api to copy the output
const outputValue = printOutput.value;
navigator.clipboard.writeText(outputValue);
alert("Password Copied!");
}
//copy the output when the copy button is pressed
copyButton.onclick = copyPassword;
let generatePassword = () => {
let length = passwordSlider.value;
// let charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let charset = "";
let output = "";
// if letters checkbox is checked
// add letters to Charset
if (lowercaseBox.checked) {
charset += "abcdefghijklmnopqrstuvwxyz";
}
if (uppercaseBox.checked) {
charset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
if (numbers.checked) {
charset += "0123456789";
}
if (specialChar.checked) {
// escape backslash with another backslash
charset += "~!@#$%^&*_-+=`|\\(){}[]:;\"'<>,.?/";
}
//getting rid of ambiguous characters
if (unambiguous.checked) {
// charset -= "l1IO0";
charset = charset.replace("l", "");
charset = charset.replace("1", "");
charset = charset.replace("I", "");
charset = charset.replace("O", "");
charset = charset.replace("0", "");
}
//add random characters from the charset to the generated password
for (let i = 0, n = charset.length; i < length; ++i) {
output += charset.charAt(Math.random() * n);
}
// print the random password
printOutput.innerHTML = output;
}
// generate random password and print the output when button is clicked
generateButton.onclick = generatePassword;