-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassRandomizer.js
More file actions
41 lines (40 loc) · 1.29 KB
/
passRandomizer.js
File metadata and controls
41 lines (40 loc) · 1.29 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
const keys = {
upperCase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
lowerCase: "abcdefghijklmnopqrstuvwxyz",
number: "1234567890",
symbol: "!@#$%^&*()_+~\`|}{[]:;?><,./-="
}
const getKey = [
function upperCase() {
return keys.upperCase[Math.floor(Math.random() * keys.upperCase.length)];
},
function lowerCase() {
return keys.lowerCase[Math.floor(Math.random() * keys.lowerCase.length)];
},
function number() {
return keys.number[Math.floor(Math.random() * keys.number.length)];
},
function symbol() {
return keys.symbol[Math.floor(Math.random() * keys.symbol.length)];
}
];
function createPassword() {
const passwordBox = document.getElementById("passwordBox");
const passLength = 16;
let password = "";
while (passLength > password.length) {
let keyToAdd = getKey[Math.floor(Math.random() * getKey.length)];
password += keyToAdd();
}
passwordBox.innerHTML = password;
}
function copyPassword() {
const textarea = document.createElement("textarea");
const password = document.getElementById("passwordBox").innerText;
if (!password) { return; }
textarea.value = password;
document.body.appendChild(textarea);
textarea.select();
document.execCommand("copy");
textarea.remove();
}