Categories > Coding > HTML >
[source] simple password generator in html & javascript
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>
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
Replied
Not bad, however I'd love to see some CSS design
Replied
Looks neat. Thanks for simple code. A bit of CSS will give it cool look.
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )