-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
57 lines (31 loc) · 1.12 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
let sliderElement = document.querySelector("#slider");
let buttonElement = document.querySelector("#button");
let sizePassword = document.querySelector("#valor");
let password = document.querySelector("#password");
let containerPassword = document.querySelector("#container_password");
let charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#_*0123456789"
let novaSenha = "";
sizePassword.innerHTML = sliderElement.value;
slider.oninput = function(){
sizePassword.innerHTML = this.value;
}
function generatePassword(){
let pass = "";
for(let i = 0, n = charset.length; i < sliderElement.value; i++){
pass += charset.charAt(Math.floor(Math.random() * n));
}
console.log(pass)
containerPassword.classList.remove("hide");
password.innerHTML = pass;
novaSenha = pass;
}
button.addEventListener('click', (event) => {
generatePassword();
})
function copyPassword(){
navigator.clipboard.writeText(novaSenha);
}
password.addEventListener('click', (event) => {
copyPassword()
alert("Senha copiada com sucesso! 🎉")
})