-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (35 loc) · 1.37 KB
/
Copy pathscript.js
File metadata and controls
44 lines (35 loc) · 1.37 KB
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 lower = true;
let upper = true;
let numbers = true;
let symbols = true;
const lowerChars = 'abcdefghijklmnopqrstuvwxyz'
const numbersChars = '0123456789'
const symbolsChars = '!@#$%^&*'
const displayGenerated = document.getElementById('generated');
const toggleLower = (() => {lower = !lower;})
const toggleUpper = (() => {upper = !upper})
const toggleNumbers = (() => {numbers = !numbers})
const toggleSymbols = (() => {symbols = !symbols})
function generatePassword() {
let passLength = document.getElementById('length').value;
if (passLength === '') {
passLength = Math.floor(Math.random() * (32-16+1)) + 16;
} else {
Number(passLength) <= 32 && Number(passLength) >= 16 ? passLength : alert('Invalid Input. (Leave Blank for a Random length)')
}
let chars = '';
lower ? chars += lowerChars : chars;
upper ? chars += lowerChars.toUpperCase() : chars;
numbers ? chars += numbersChars : chars;
symbols ? chars += symbolsChars : chars;
chars === '' ? alert('Select at least one character set') : chars;
let password = '';
for (let i = 0; i < passLength; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length))
}
displayGenerated.textContent = password;
}
const copy = (() => {
const copyText = document.getElementById('generated').textContent;
navigator.clipboard.writeText(copyText);
})