In this tutorial we will create a How to Generate a Random Password for Multiple User in JavaScript. This tutorial purpose is to teach you how to generate a random password for users. This will cover all the basic function that will update your array data. I will provide a sample program to show the actual coding of this tutorial.
This tutorial is simple and easy to understand just follow the instruction I provided and you can do it without a problem. This program can be use to any system or application that require password for login. I will give my best to provide you the easiest way of creating this program Random Password for all user. So let's do the coding.
This is the link for the template that i used for the layout design https://getbootstrap.com/.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body onload="displayUser();"> <nav class="navbar navbar-default"> <div class="container-fluid"> </div> </nav> <div class="col-md-6 well"> <hr style="border-top:1px dotted #ccc;"/> <table class="table table-bordered"> <thead class="alert-info"> <tr> </tr> </thead> </table> </div> </body> </html>
var names=["John Smith", "Claire Temple", "Steve Roger", "Jessie Mendoza", "Richard Max"]; var username=["john", "claire12", "steve114", "jessie0001", "rich23"]; var password=[]; function displayUser(){ var html=""; for(var i=0; i<5; i++){ html+="<tr><td>"+names[i]+"</td><td>"+username[i]+"</td><td></td></tr>"; } document.getElementById('result').innerHTML=html; } function generatePasswords(){ var html=""; for(var i=0; i<5; i++){ password.push(randomPassword()); } for(var i=0; i<5; i++){ html+="<tr><td>"+names[i]+"</td><td>"+username[i]+"</td><td>"+password[i]+"</td></tr>"; } document.getElementById('result').innerHTML=html; password=[]; } function randomPassword(){ var characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var newPassword = ""; for(var i = 0, j = characters.length; i < 12; i++){ newPassword += characters.charAt(Math.floor(Math.random() * j)); } return newPassword; }
In the code above we will first create a method that we will call randomPassword(), this function will generate random characters that will act as the password. We use loop to loop thought the character and use the Math() function to get a randomize result. In order to display the password we will create a method called generatePasswords(), this function will append the random password to the html table when the button is triggered.
The How to Generate a Random Password for Multiple User in JavaScript source code that I provide can be download below. Please kindly click the download button.
There you have it we successfully created How to Generate a Random Password for Multiple User in JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
More Tutorials for JavaScript Language