vnm0
Infinity Member
- Joined
- October 16, 2024
- Messages
- 168
- Reaction score
- 1,279
- Points
- 93
- Thread Author
- #1
Code:
<!DOCTYPE html>
<html>
<head>
<title>Password Generator</title>
</head>
<body>
<h1>Password Generator</h1>
<button id="generate">Generate Password</button>
<input type="text" id="password" readonly>
<script>
// Function to generate a random password
function generatePassword(length) {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+";
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
password += charset[randomIndex];
}
return password;
}
// Function to update the password input field
function updatePasswordField() {
const passwordField = document..value = generatePassword(passwordLength);
}
// Attach the function to the "Generate Password" button
const generateButton = document..addEventListener("click", updatePasswordField);
// Generate an initial password when the page loads
updatePasswordField();
</script>
</body>
</html>