-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
25 lines (24 loc) · 976 Bytes
/
index.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
const passwordBox = document.getElementById("password");
const copyBtn = document.getElementById("copy");
const generateBtn = document.getElementById("generate");
const length = 12;
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowercase = "abcdefghijklmnopqrstuvwxyz";
const numbers = "0123456789";
const symbols = "!@#$%^&*()_+<>?";
const allChars = uppercase + lowercase + numbers + symbols;
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 += symbols[Math.floor(Math.random() * symbols.length)];
while(password.length < length){
password += allChars[Math.floor(Math.random()*allChars.length)];
}
passwordBox.value = password;
}
function copyPassword(){
passwordBox.select();
document.execCommand("copy");
}