Categories > Coding > HTML >

[source] simple password generator in html & javascript

Posts: 15

Threads: 6

Joined: Dec, 2022

Reputation: 2

Posted

Lmao, im in the wave.

 

Source code:

<!DOCTYPE html>
<html>
<head>
  <title>Password Generator</title>
</head>
<body>
  <h1>Password Generator</h1>
  <button onclick="generatePassword()">Generate Password</button>
  <p id="password"></p>

  <script>
    function generatePassword() {
      const length = 8;

      const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%";
      const specialCharacters = "!@#$%";

      let password = "";

      for (let i = 0; i < length; i++) {
        password += characters.charAt(Math.floor(Math.random() * characters.length));
      }

      let includesSpecial = false;
      for (let i = 0; i < specialCharacters.length; i++) {
        if (password.includes(specialCharacters.charAt(i))) {
          includesSpecial = true;
          break;
        }
      }

      if (!includesSpecial) {
        password = password.substring(0, password.length - 1) + specialCharacters.charAt(Math.floor(Math.random() * specialCharacters.length));
      }

      document.getElementById("password").textContent = password;
    }
  </script>
</body>
</html>

 

  • 0

Posts: 2014

Threads: 198

Joined: Apr, 2021

Reputation: 16

Replied

Not bad, however I'd love to see some CSS design

  • 1

Random quote here...

Posts: 1

Threads: 0

Joined: Mar, 2023

Reputation: 0

Replied

Looks neat. Thanks for simple code. A bit of CSS will give it cool look. 

  • 1

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )