Generate Random Password with Special Characters

Below given function will generate a random password including special characters.

function generatePswdString(max, min) {

      const passwordChars = “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#@!%& ()/”;

      const randPwLen = Math.floor(Math.random() * (max – min + 1)) + min;

      var randomPassword = “”;

      for (var i = 0; i < randPwLen; i++) {

         var randomIndex = Math.floor(Math.random() * (passwordChars.length));

          randomPassword += passwordChars.charAt(randomIndex);

      }

      log.debug(“randomPassword”, randomPassword);

      return randomPassword;

    }

Leave a comment

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