-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
30 lines (28 loc) · 1.18 KB
/
main.js
File metadata and controls
30 lines (28 loc) · 1.18 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
// Get the password input box element by its ID
const passwordBox = document.getElementById('password');
// Set the length of the password to be generated
const length = 20;
// Define the characters that can be used in the password
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+~`|}{[]\\:;?><,./-=";
// Function to generate a random password
function generatePassword() {
let password = "";
// Loop to generate each character of the password
for (let i = 0; i < length; i++) {
// Get a random index from the charset
let randomIndex = Math.floor(Math.random() * charset.length);
// Append the character at the random index to the password
password += charset[randomIndex];
}
// Set the value of the password input box to the generated password
passwordBox.value = password;
}
// Function to copy the generated password to the clipboard
function copyPassword() {
// Select the text in the password input box
passwordBox.select();
// Execute the copy command
document.execCommand('copy');
// Alert the user that the password has been copied
alert('Password copied to clipboard!');
}