-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
44 lines (39 loc) · 1.52 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
let empty = '';
let ucase = 'ABCDEFGHIJKLMNOPQWSTUVWXYZ';
let lcase = 'abcdefghijklmnopqrstuvwxyz';
let num = '0123456789';
let sym = '!@#$%^&*';
const password__length = document.querySelector('#password__length');
const password = document.querySelector('#password')
const uppercase = document.querySelector('#uppercase');
const lowercase = document.querySelector('#lowercase');
const number = document.querySelector('#number');
const symbol = document.querySelector('#symbols');
const submit__button = document.querySelector('#submit');
submit__button.onclick = () => {
let intarnalPassword = empty;
(uppercase.checked) ? intarnalPassword += ucase: "";
(lowercase.checked) ? intarnalPassword += lcase: "";
(number.checked) ? intarnalPassword += num: "";
(symbol.checked) ? intarnalPassword += sym: "";
password.value = generate__password(password__length.value, intarnalPassword)
}
const generate__password = (langth, intarnalPassword) => {
let pass = "";
let intarnal__password__len = intarnalPassword.length
for (let i = 0; i < langth; i++) {
pass += intarnalPassword.charAt(Math.round(Math.random() * intarnal__password__len))
}
password.innerHTML = pass
return pass
}
const copy = document.querySelector('#copy')
copy.onclick = () => {
if (password.value == "") {
alert("please generat a password")
} else {
password.select()
document.execCommand('copy')
alert("password has been copied to clipboard")
}
}