-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (24 loc) · 1006 Bytes
/
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
document.addEventListener('DOMContentLoaded', function() {
const slider = document.getElementById('myRange');
const lengthDisplay = document.getElementById('lengthDisplay');
const passwordDisplay = document.getElementById('passwordDisplay');
const generateButton = document.getElementById('generate');
const copyButton = document.getElementById('copy');
slider.oninput = function() {
lengthDisplay.textContent = this.value;
}
generateButton.onclick = function() {
passwordDisplay.value = generatePassword(slider.value);
}
copyButton.onclick = function() {
navigator.clipboard.writeText(passwordDisplay.value);
}
function generatePassword(length) {
const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@#$';
let retVal = '';
for (let i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
});