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
Not bad, however I'd love to see some CSS design
Cancel
Post
Random quote here...
Replied
Looks neat. Thanks for simple code. A bit of CSS will give it cool look.
Cancel
Post
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Cancel
Post