-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (35 loc) · 1.3 KB
/
script.js
File metadata and controls
45 lines (35 loc) · 1.3 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
45
const passBox = document.getElementById("password");
// const length = 12;
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXWZ"
const lowerCase = "abcdefghijklmnopqrstuvwxyz"
const number = "0123456789"
const symbole = "!@#$%&()+=-?/><~/|\[{}]";
const allchars = upperCase + lowerCase + number + symbole;
function createPass() {
const selectRadio = document.querySelector('input[name="length"]:checked');
// // Find the selected length
// checkBoxes.forEach(checkBox => {
// if(checkBox.checked) {
// selectedLength = parseInt(checkBox.value, 10);
// }
// });
if(!selectRadio) {
alert("Please select a password length.");
return;
}
const selectedLength = parseInt(selectRadio.value, 10);
// Gives random Password everytime.
let password = '';
// As there are only 4 letters generated so we do this loop for generating password that satisfy our pass length.
for(let i=0; i<selectedLength; i++) {
const randomIndex = Math.floor(Math.random() * allchars.length);
password += allchars[randomIndex];
}
passBox.value = password;
}
// Used to copy Password
function copyPass(){
passBox.select();
document.execCommand("copy");
alert("Password copied to clipboard!");
}