-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
45 lines (34 loc) · 1.27 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
38
39
40
41
42
43
44
45
/* ===( CODE AASHU )=== */
const passwordInput = document.getElementById('password-input');
const button = document.querySelector('.btn');
const copyButton = document.querySelector('.copy-btn');
const messageBox = document.getElementById('message-box');
const length = 8;
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const lowerCase = upperCase.toLowerCase();
const numbers = "0123456789";
const symbol = "@#*";
const allChar = upperCase + lowerCase +numbers +symbol;
function createPassword(){
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 += symbol[Math.floor(Math.random()*symbol.length)];
while(length>password.length){
password += allChar[Math.floor(Math.random()*allChar.length)];
}
passwordInput.value= password;
}
button.addEventListener('click', ()=>{
createPassword();
messageBox.style.scale = '0';
})
function copyText(){
passwordInput.select();
document.execCommand("copy");
};
copyButton.addEventListener('click', ()=>{
copyText();
messageBox.style.scale = '1';
});