password-generator


DEMO



Step by Step Algorithm:

1. Create an HTML document with a head and body element. In the head, specify the character encoding, viewport, and link to a stylesheet. In the body, create a div element with an id of "password-generator".

2. Inside the "password-generator" div, create a button element with an id of "generate-button". This will be used to allow the user to generate a new password.

3. Below the button, create a p element with text content "Password: " followed by a span element with an id of "password". This element will be used to display the generated password.

4. At the bottom of the body, include a script element with a src attribute that points to the JavaScript file that will contain the logic for generating the password.

5. In the JavaScript file, create a function that will be called when the "generate-button" is clicked. This function will be responsible for generating the password.

6. Inside the function, use a combination of string concatenation and random number generation to create a password of the desired length. For example, you could generate a random number between 0 and 25 to choose a letter from the alphabet, and then concatenate that letter to a string that will be used to build the password.

7. Use DOM manipulation techniques to update the text content of the "password" span element with the generated password.

8. Add an event listener to the "generate-button" that calls the function when the button is clicked.

HTML:


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Random Password Generator></title>
</head>
<body> 
<div id="password-generator">
<button id="generate-button">Generate password></button>
<p>Password: <span id="password"></span></p>
</div>
<script src="app.js"></script> 
</body>
</html>


CSS:

*{
margin: 0%;
padding: 0%;
box-sizing: border-box;
}

#password-generator {
width: 50%;
margin: 10% auto;
text-align: center;
font-family: sans-serif;
display: flex;
flex-direction: column;
gap:30px;
}

button {
background-color: lightblue;
border: none;
padding: 5px 10px;
cursor: pointer;
}

button:hover {
background-color: skyblue;
}


Step by Step Algorithm:

1. Select the generate-button element from the HTML document using the getElementById method.

2. Add an event listener to the generate-button element that listens for a "click" event and calls an anonymous function when the event is triggered.

3.Inside the anonymous function, initialize an empty string variable called password.

4. Define a string of possible characters to use for the password.

5. Use a for loop to iterate 8 times. On each iteration, use the Math.random and Math.floor methods to generate a random index between 0 and the length of the possibleCharacters string. Use the charAt method to get the character at this index in the possibleCharacters string and add it to the password string.

6. Select the password element from the HTML document using the getElementById method and set its innerHTML property to the value of the password string.

Java Script:


document.getElementById('generate-button').onclick = function() {
// generate a random password
var password = '';
var possibleCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i = 0; i < 8; i++) {
password += possibleCharacters.charAt(Math.floor(Math.random() * possibleCharacters.length));
}

// display the password
document.getElementById('password').innerHTML = password;
};




You can improve this project in your own version.

We are ready to release more projects please support us by sharing and visiting webdevmonk