-
Notifications
You must be signed in to change notification settings - Fork 903
/
Copy pathscript.js
29 lines (25 loc) · 1.04 KB
/
script.js
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
const btn = document.getElementById('gen-pwd');
const passwordBox = document.getElementById('password');
const imgCopy = document.getElementById('copyImg');
const length = 8;
const upperCase = 'ABCDEFGHIJKLMNOPQRSTUVQXYZ';
const lowerCase = 'abcdefghijklmnopqrstuvwxyz';
const numbers = '0123456789';
const symbols = '~!@#$%^&*_?/';
const allChars = upperCase + lowerCase + numbers + symbols;
btn.addEventListener('click', () => {
let password = "";
password += upperCase[Math.floor(Math.random() * (upperCase.length))];
password += lowerCase[Math.floor(Math.random() * (lowerCase.length))];
password += numbers[Math.floor(Math.random() * (numbers.length))];
password += symbols[Math.floor(Math.random() * (symbols.length))];
while (length > password.length) {
password += allChars[Math.floor(Math.random() * (allChars.length))];
}
passwordBox.value = password;
})
imgCopy.addEventListener('click', () => {
passwordBox.select();
//copies the current selection into the clipboard
document.execCommand("copy");
})