Source Code Password Generator

Currently reading:
 Source Code Password Generator

xyline

Member
LV
1
Joined
Aug 9, 2023
Threads
11
Likes
7
Awards
4
Credits
1,035©
Cash
0$
HTML:
<!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.getElementById("password");
            const passwordLength = 12; // You can change this to your desired password length
            passwordField.value = generatePassword(passwordLength);
        }

        // Attach the function to the "Generate Password" button
        const generateButton = document.getElementById("generate");
        generateButton.addEventListener("click", updatePasswordField);

        // Generate an initial password when the page loads
        updatePasswordField();
    </script>
</body>
</html>
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips

Similar threads

Replies
47
Views
1K
Top Bottom