-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
63 lines (56 loc) · 1.74 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const generateP = document.getElementById('generate');
const passP = document.getElementById("generatedPassword");
const copyP = document.getElementById("copy");
const lenP = document.getElementById("len");
const upperP = document.getElementById("upper");
const lowerP = document.getElementById("lower");
const symbolP = document.getElementById("symbol");
const numberP = document.getElementById("number");
const upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lower = "abcdefghijklmnopqrstuvwxyz";
const numbers = "0123456789";
const symbol = "~!@#$%^&*()_-+=|";
function getLower() {
return lower[Math.floor(Math.random() * lower.length)]
}
function getUpper() {
return upper[Math.floor(Math.random() * upper.length)]
}
function getNumber() {
return numbers[Math.floor(Math.random() * numbers.length)]
}
function getSymbol() {
return symbol[Math.floor(Math.random() * symbol.length)]
}
function generateX() {
const xs = [];
if(upperP.checked){
xs.push(getUpper())
}
if(lowerP.checked){
xs.push(getLower())
}
if(numberP.checked){
xs.push(getNumber())
}
if(symbolP.checked){
xs.push(getSymbol())
}
if(xs.length === 0) return "";
return xs[Math.floor(Math.random() * xs.length)];
}
function generatePass() {
let password = "";
const length = lenP.value;
for( var i=0; i<length; i++)
{
const x = generateX();
password += x;
}
document.getElementById("generatedPassword").innerText = password;
}
function copyPassword() {
const copyText = document.getElementById('generatedPassword');
navigator.clipboard.writeText(copyText.textContent);
alert("Password successfully copied");
}