Strong Password Generator With Custom Rules - Password.js

File Size: 4.09 KB
Views Total: 3983
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Strong Password Generator With Custom Rules - Password.js

A lightweight (2kb) and easy-to-use jQuery plugin used for randomly generate strong, complex password strings that match sets of rules you specify.

Default rules:

  • 12 letters and numbers
  • 4 special characters.

How to use it:

1. Include both jQuery library and the password.js script at the bottom of the webpage.

<script src="//"></script>
<script src="js/password.js"></script>

2. Create a normal password field as follow:

<input type="text" id="password">

3. Create a 'Generate' button to generate random strings in the password field you just created.

<button onclick="$('#password').val(password.generate());">
  Generate Password

4. Override the default rules in the password.js

// Add another object to the rules array here to add rules.
// They are executed from top to bottom, with callbacks in between if defined.
rules: [

  //Take a combination of 12 letters and numbers, both lower and upper case.
    characters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890',
    max: 12

  //Take 4 special characters, use the callback to shuffle the resulting 16 character string
    characters: '!@#$%^&*()_+|~-={}[]:";<>?,./',
    max: 4,
    callback: function (s) {
      var a = s.split(""),
          n = a.length;

      for (var i = n - 1; i > 0; i--) {
          var j = Math.floor(Math.random() * (i + 1));
          var tmp = a[i];
          a[i] = a[j];
          a[j] = tmp;
      return a.join("");

This awesome jQuery plugin is developed by KekoApp. For more Advanced Usages, please check the demo page or visit the official website.