-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword.js
More file actions
43 lines (30 loc) · 1.26 KB
/
password.js
File metadata and controls
43 lines (30 loc) · 1.26 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
const passwordBox = document.getElementById('password');
const lenght = 12;
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowerCase = "abcdefghijklmnopqrstuvwxyz";
const number = "0123456789";
const symbol = "@#$%^&*()_=~|}{][></-=";
const allChars = upperCase + lowerCase + number + symbol;
function createPassword() {
let password = "";
password += upperCase[Math.floor(Math.random() * upperCase.length)];
password += lowerCase[Math.floor(Math.random() * lowerCase.length)];
password += number[Math.floor(Math.random() * number.length)];
password += symbol[Math.floor(Math.random() * symbol.length)];
while (lenght > password.length) {
password += allChars[Math.floor(Math.random() * allChars.length)];
}
passwordBox.value = password;
}
function copy() {
passwordBox.select();
document.execCommand("copy");
const copyButton = document.getElementById('copyButton');
const copyIcon = copyButton.querySelector('img');
copyButton.innerHTML = '<img src="/images/copied.png">Copied Password';
copyButton.style.backgroundColor = '#006F3B';
setTimeout(function () {
copyButton.innerHTML = '<img src="/images/copy.png">Copy Password';
copyButton.style.backgroundColor = '';
}, 1000);
}