- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a password generator - JavaScript?
For this, use Math.random() to create random passwords.
Example
Following is the code −
function makePassword(maxLengthPass) { var collectionOfLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var generatedPassword = ""; var size = collectionOfLetters.length; for (var i = 0; i < maxLengthPass; ++i) { generatedPassword = generatedPassword + collectionOfLetters.charAt(Math.floor(Math.random() * size)); } return generatedPassword; } console.log(makePassword(5));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo287.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo287.js eeVK0
- Related Articles
- How to create a password validation form with CSS and JavaScript?
- How to create a password field using JavaFX?
- How to create a password entry field using Tkinter?
- How to create a Password Entry Field in Tkinter?
- JavaScript Generator
- How to Toggle Password Visibility in JavaScript?
- How to toggle between password visibility with JavaScript?
- Validating a password using JavaScript
- How to build a random quote generator using HTML, CSS, and JavaScript?
- Can generator be used to create iterators in Python?
- How to Choose a Secure Password?
- Explain Generator functions in JavaScript?
- Random color generator in JavaScript
- Create a new user with password in MySQL 8?
- Validating email and password - JavaScript

Advertisements