Online custom password generator
Online custom password generator

This is an online example on how to create a password generator. This password generator is written using Javascript.
You can combine four parameters to create the password :

  • upper case letter
  • lower case letter
  • number
  • special character

The minimum length requirement for a strong password is 13 characters. For an Active Directory environment this length will protect you from brute force attack using the free and downloadable Rainbow Tables. You can find here an example on how to test your Active Directory user password strength.

The complexity requirements for a password in the Active Directory domain is the following:

  • Not contain the user’s account name or parts of the user’s full name that exceed two consecutive characters
  • Be at least six characters in length
  • Contain characters from three of the following four categories:
  • English uppercase characters (A through Z)
  • English lowercase characters (a through z)
  • Base 10 digits (0 through 9)
  • Non-alphabetic characters (for example, !, $, #, %)

Complexity requirements are enforced when passwords are changed or created.

With this custom password generator you can set the number of characters and type you want to include in it :

  • Uppercase characters = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”
  • Lowercase characters = “abcdefghijklmnopqrstuvwxyz”
  • Numbers = “0123456789”
  • Special characters = “+-_,;.:?!%=”

Upper
Lower
Number
Special
Click on the button "Generate Password"

   

Source code:

<html>
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                <link href="css/bootstrap.min.css" rel="stylesheet" />

                <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

                <script>
                var upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                var lower = "abcdefghijklmnopqrstuvwxyz";
                var numbr = "0123456789";
                var special = "+-_,;.:?!%=";

                function randChar(param_arr,nbr){
                        randreturn = "";
                        for (var i=0; i<nbr; i++){
                                randreturn += param_arr.charAt(Math.floor(Math.random() * param_arr.length));
                        }
                        return randreturn;
                }

                function getParam(){
                        var upper_nb=parseInt($('#upper_select').find(":selected").val());
                        var lower_nb=parseInt($('#lower_select').find(":selected").val());
                        var numbr_nb=parseInt($('#number_select').find(":selected").val());
                        var special_nb=parseInt($('#special_select').find(":selected").val());
                        var total_nb=upper_nb+lower_nb+numbr_nb+special_nb;

                        upper_rand = randChar(upper,upper_nb);
                        lower_rand = randChar(lower,lower_nb);
                        numbr_rand = randChar(numbr,numbr_nb);
                        special_rand = randChar(special,special_nb);

                        final_not_rand = upper_rand + lower_rand + numbr_rand + special_rand;
                        final_not_rand_arr=final_not_rand.split('');
                        final_rand=final_not_rand_arr.sort(function() { return 0.5 - Math.random() });

                        $("#GenPass_field").text(final_rand.join(''));
                }
                </script>
        </head>
        <body>
                <div>
                Uppercase characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"<br>
                Lowercase characters = "abcdefghijklmnopqrstuvwxyz"<br>
                Numbers = "0123456789"<br>
                Special characters = "+-_,;.:?!%="<br>
                <br>
                </div>
                <div style="display:block;float:left;width:60px;">
                Upper
                <select id="upper_select">
                        <option value=0>0</option>
                        <option value=1>1</option>
                        <option value=2>2</option>
                        <option value=3>3</option>
                        <option value=4 selected="selected">4</option>
                        <option value=5>5</option>
                        <option value=6>6</option>
                        <option value=7>7</option>
                        <option value=8>8</option>
                        <option value=9>9</option>
                </select>
                </div>
                <div style="display:block;float:left;width:60px;">
                Lower
                <select id="lower_select">
                        <option value=0>0</option>
                        <option value=1>1</option>
                        <option value=2>2</option>
                        <option value=3>3</option>
                        <option value=4>4</option>
                        <option value=5 selected="selected">5</option>
                        <option value=6>6</option>
                        <option value=7>7</option>
                        <option value=8>8</option>
                        <option value=9>9</option>
                </select>
                </div>
                <div style="display:block;float:left;width:60px;">
                Number
                <select id="number_select">
                        <option value=0>0</option>
                        <option value=1>1</option>
                        <option value=2>2</option>
                        <option value=3 selected="selected">3</option>
                        <option value=4>4</option>
                        <option value=5>5</option>
                        <option value=6>6</option>
                        <option value=7>7</option>
                        <option value=8>8</option>
                        <option value=9>9</option>
                </select>
                </div>
                <div style="display:block;float:left;width:60px;">
                Special
                <select id="special_select">
                        <option value=0>0</option>
                        <option value=1>1</option>
                        <option value=2 selected="selected">2</option>
                        <option value=3>3</option>
                        <option value=4>4</option>
                        <option value=5>5</option>
                        <option value=6>6</option>
                        <option value=7>7</option>
                        <option value=8>8</option>
                        <option value=9>9</option>
                </select>
                </div>
                <br><br><br>
                <div><button onclick="getParam()" class="btn" type="button">Generate Password</button></div>
                <div><span id="GenPass_field"></span></div>
        </body>
</html>

Reference

Math.random()

Summary

The Math.random() function returns a floating-point, pseudo-random number in the range[0, 1) that is, from 0 (inclusive) up to but not including 1 (exclusive), which you can then scale to your desired range.  The implementation selects the initial seed to the random number generation algorithm; it cannot be chosen or reset by the user.

Note: Math.random() does not provide cryptographically secure random numbers. Do not use them for anything related to security. Use the Web Crypto API instead, and more precisely thewindow.crypto.getRandomValues() method.

Syntax

Math.random()

Parameters

None.

Examples

Example: Using Math.random

Note that as numbers in JavaScript are IEEE 754 floating point numbers with round-to-nearest-even behavior, the ranges claimed for the functions below (excluding the one for Math.random() itself) aren't exact.  If extremely large bounds are chosen (253 or higher), it's possible in extremely rare cases to calculate the usually-excluded upper bound.

// Returns a random number between 0 (inclusive) and 1 (exclusive)
function getRandom() {
  return Math.random();
}
// Returns a random number between min (inclusive) and max (exclusive)
function getRandomArbitrary(min, max) {
  return Math.random() * (max - min) + min;
}
// Returns a random integer between min (included) and max (excluded)
// Using Math.round() will give you a non-uniform distribution!
function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}

Specifications

Specification Status Comment
ECMAScript 1st Edition. JavaScript 1.0 (UNIX Only) / JavaScript 1.1 (All platform) Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
The definition of 'Math.random' in that specification.
Standard
ECMAScript 6 (ECMA-262)
The definition of 'Math.random' in that specification.
Draft

 

<>
Online custom password generator
Tagged on:     

Leave a Reply

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