Generating Fixed-Length Random Passwords

Modified on Mon, Sep 15 at 2:53 PM

Generating Passwords with ReportWriter

It is possible to use the ReportWriter to generate random passwords.  Using the techniques discussed here, the ReportWriter will generate a new set of passwords each time it runs.


The primary use for these techniques is to output the passwords into a spreadsheet.  The spreadsheet can then be uploaded to save the passwords into a system.


Fixed-Length Random Passwords

To generate passwords, you must generate a set of randomly chosen characters.  For example, upper case letters, lower case letters, numbers and special characters.  The techniques described here allow you to choose random characters and assemble them into a fixed length password.  



Choosing Characters for the Generated Passwords


Choosing an Upper Case Letter

${ rw:toUpperCase(rw:substring(params.ALPHABET,rw:randomNumber(26)-1,1)) }


Choosing a Lower Case Letter

This expression simply picks a random letter from the lower case alphabet found in the ALPHABET parameter (see below):

${ rw:substring(params.ALPHABET,rw:randomNumber(26)-1,1) }


The letters in the ALPHABET parameter are in their normal order - the random number just picks one of the letters out of the list.  If you put the letters in the parameter in 'random' order, you get two levels of random selection.


Choosing a Character from a String of Mixed Characters

${rw:randomNumber(2)==0? rw:substring(params.MIXEDCHARS,rw:randomNumber(34)-1,1) : rw:toUpperCase(rw:substring(params.MIXEDCHARS,rw:randomNumber(34)-1,1))}


${ rw:substring(params.SPECIALS,rw:randomNumber(8)-1,1) }


Generating a Single Digit Number (in the Range 0 to 9)

${ rw:randomNumber(10)-1 }


Combining Characters into a Single Password

The expression below concatenates a set of columns into a single password.  Each column, here named rando1 to rando9, is concatenated into the whole.  The 'concat5' function is used multiple times to bind all of the individual 'random' columns into the whole:

${rw:concat5(row.rando1,row.rando2,row.rando5,row.rando6,rw:concat(row.rando4a,rw:concat5(row.rando3,row.rando4,row.rando7,row.rando8,row.rando9))) }


The Key Function:  rw:randomNumber

The randomNumber function takes an integer value - call it X - and produces a number between 1 and X.  It will never produce the number 0 (zero).


Integer randomNumber(integer X)


For example, rw:randomNumber(26) will produce a number between 1 and 26, inclusive.  


When using the result of a call to rw:randcomNumber to select a character in a "Source String" (see below), you must adjust the value down by 1:   rw:randomNumber(26)-1 will select a number in the range 0 to 25.    The first character in a String is in the "zeroth position" - you need to subtract 1 from the generated rw:fandomNumber result to be able to select the first character in a String (which is in "position 0").  


For example, to get a single digit in the range 0 to 9, you must use "10" as your X:

${ rw:randomNumber(10)-1 }



Defining 'Source String' Parameters

The "source string" parameters are a set of "invisible" parameters used to contain the list(s) of characters that will be used to randomly generate the passwords.  In the example below, three 'source strings' are defined:

- the "SPECIALS" string contains a set of special characters that can appear in the passwords:  !@#$Za%&*

- The ALPHABET string contains the regular alphabet all in lower case.

- The MIXED CHARS string contains both the alphabet and the special characters, somewhat randomly inserted in the middle

There is no "NUMBERS" set because in this example, the numbers are generated directly from the random number generator.


Source Strings

A 'source string' in this technique is simply a list of characters you want to include in the passwords.  While in the example shown the ALPHABET string is - in fact - the alphabet in regular order.  But source string need not follow regular order:  they can be a String of any length in any order you desire.   To use this technique as designed, you will need to create at least one source string.



Creating the Password Generation Columns

There are multiple ways to generate the random characters that will be combined into a single 'random' password.  In this example each random character is produced into its own separate column.   There are 10 'random generation' columns, as shown in the image below and a final column where the individual characters are assembled into a password:


In this example, each of the "rando" columns contains one of the Expressions described above:  it either selects a lower case letter, an upper case letter, a special character or a single random digit.   In the final "password" column at bottom, all of the 'rando' single characters are combined into a fixed length password:  all of the passwords generated have 10 characters (one from each 'rando' column).  Note that this is NOT the only way to generate and combine random characters.   You can create a single column and pack a set of character generating Expressions into it.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article