Categories > Coding > HTML >

[source] simple password generator in html & javascript


New Reply

Posts: 15

Threads: 6

Joined: Dec, 2022

Reputation: 2

  • 0

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>

 

Posts: 5

Threads: 1

Joined: Jan, 2023

Reputation: 2

  • 0

Replied

Hello this is Gulshan Negi

Thanks for such useful information with coding. Well here is the simplest code for password generator in HTML.

 

<!DOCTYPE html> <html> <head> <title>Password Generator</title> </head> <body> <h1>Password Generator</h1> <button id="generate-btn">Generate Password</button> <p id="password"></p> </body> <script src="password-generator.js"></script> </html>

 

Thanks

 

 

Posts: 1918

Threads: 179

Joined: Apr, 2021

Reputation: 17

  • 0

Replied

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

Posts: 1

Threads: 0

Joined: Mar, 2023

Reputation: 0

  • 0

Replied

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


New Reply

Users viewing this thread:


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