-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (23 loc) · 763 Bytes
/
script.js
File metadata and controls
27 lines (23 loc) · 763 Bytes
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
const genBtn = document.querySelector(".btn1");
const copyBtn = document.querySelector(".btn2");
genBtn.addEventListener("click", function(){
genPassword();
});
copyBtn.addEventListener("click", function(){
copyPassword();
} );
function genPassword() {
let chars = "0123456789abcdefghijklmnopqristuvwxyz!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ";
passwordLength = 8;
password = "";
for (let i = 0; i <= passwordLength; i++) {
let randomNumber = Math.floor(Math.random() * chars.length);
password += chars.substring(randomNumber, randomNumber + 1);
}
document.getElementById("password").value = password;
}
function copyPassword() {
let copyText = document.getElementById("password");
copyText.select();
document.execCommand("copy");
}