How to Generate Random Password in Javascript


In this video tutorial, you will learn how to generate random password in javascript.  There are multiple ways to generate random password, but I found this easy to use password=generator library. It comes with a bunch of features which can be helpful in generating a random password.

This library also gives you ability to detect if the password entered by user is strong enough or not.  That is out of scope of this tutorial, so I will recommend you to have a look over their gtihub repo to learn more about this library.


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <script src="js/password-generator.min.js"></script>
    <script src="js/script.js"></script>



div {
    display: flex;
    flex-direction: column;
    align-items: center;

button {
    padding: 10px;



let btnGenerate = document.querySelector('button');
let result = document.querySelector('h1');

btnGenerate.addEventListener('click', () => {
   result.innerText = generatePassword(25, false, '', 'kodebase-');