forked from Avdhesh-Varshney/blog-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (30 loc) · 1.16 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
30
31
32
33
34
35
36
37
const passwordBox = document.getElementById("password");
const length = 12;
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowerCase = "abcdefghijklmnopqrstuvwxyz";
const number = "01223456789";
const symbols = "@#$%^&*()_=~{}[]<>/-=";
const allChars=upperCase+lowerCase+number + symbols;
function generatePassword(){
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+=symbols[Math.floor(Math.random()*symbols.length)];
while(length>password.length){
password+=allChars[Math.floor(Math.random()*allChars.length)];
}
passwordBox.value=password;
}
async function copyPassword(){
const passwordBox = document.getElementById("password");
passwordBox.select();
try {
const textToCopy = passwordBox.value;
await navigator.clipboard.writeText(textToCopy);
console.log("Password copied to clipboard");
} catch (err) {
console.error("Error copying password to clipboard", err);
}
window.getSelection().removeAllRanges();
}