Generate a random password using JavaScript

Today we’ll show you how to generate a random password using JavaScript. Here, we’ll show you the most popular two methods to generate a random strong password using JavaScript.

Ways to generate a random password

  1. Generate a password from given string
  2. Use Math.random() method

1. Generate a password from given string

In this approach, we will create a custom function to get a random password where we have to pass the length of the password as a parameter. We’ll consider the string, number and symbol to generate a random password.

2. Use Math.random() method

In the next approach, we’ll use the Math.random() method to cast a random number (in the range 0..1) to a base36 string (lowercase a-z plus 0-9) and remove the leading zero and decimal point using slice() method. Here, we have used the toUpperCase() method to get the uppercase char in the password.

That’s it for today.
Thank you for reading. Happy Coding..!!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *