WillMaster Possibillites Logo EzineSeek Award
Master Password Generator V1
by
Mari Bontrager

Permission is granted to reprint this article in its entirety, provided no reprints are sent in conjunction with unsolicited bulk email, provided no fee or other value is exchanged, provided no changes are made to the article, and provided the author's name, signature lines, and copyright line are printed with the article; except you may change the article's title.

This article talks about Master Password Generator V1, a free Master Series CGI program.

It also talks about incorporating the password generating subroutine, developed for Master Password Generator V1, into your own scripts.

If you want to go straight to the product description page to try the demo or download the program, here is the URL: http://willmaster.com/a/17/pl.pl?art172

Automatic password generation can be desired for many and varied reasons. Here are a few.

~~ For webmasters selling downloadable products, like ebooks or software, where a unique password is provided with each sale.

~~ For personal use, when a password is desired that's not easily guessable.

~~ Membership software, where new members must be assigned a password.

Master Password Generator V1

When you use Master Password Generator V1, you'll find three form fields for numbers and five checkboxes.

The three form fields for numbers are all optional:

  1. The number of passwords you want generated. If not filled in, 1 is assumed.

  2. The minimum length for each password. If not filled in, 7 is assumed.

  3. The maximum length for each password. If not filled in, 7 is assumed.

As you can see, you can generate any number of passwords, with variable lengths.

The checkboxes tell Master Password Generator V1 which character set or sets to use when generating the password or passwords. At least one of the five checkboxes must be checked:

  1. A character set composed of digits. If an alphabet set is also checked, the digits 0 and 1 are not included because they can easily be confused with the letter O or the letter l.

  2. A capitalized alphabet set, excluding the letter O.

  3. An alphabet set of lower-case characters, excluding the letter l.

  4. A set of non-alphanumeric printable characters.

  5. The space character.

Simply check the checkboxes you want to use for your passwords. Then click the submit button.

Installation

Master Password Generator V1 is simple to install. Just verify that the first line of the script points to the location of perl on your server, upload the script, and give it 755 permissions. The README.txt file, included in the download package, has instructions.

To use Master Password Generator V1, type its URL into your browser. Example:

http://domain.com/cgi-bin/MasterPasswordGenerator.cgi

That URL will display the control panel in your browser.

The Password Generating Subroutine

The subroutine in Master Password Generator V1 that generates passwords is MakePassword()

To give your own script password generation functionality, paste the subroutine into your script. Here is the subroutine in its entirety:

sub MakePassword
{
   my($composition,$lowlength,$highlength) = @_;
   return '' unless $composition;
   my @p = split //,$composition;
   my $arraylength = @p;
   $lowlength = 7 if $lowlength < 1;   # default to 7.
   $highlength = 7 if $highlength < 1; # default to 7.
   if($lowlength > $highlength)
   {
      ($highlength,$lowlength) = ($lowlength,$highlength);
   }
   my $length = int(rand($highlength - $lowlength + 1));
   $length += $lowlength;
   my $password = '';
   for(1..$length)
   {
      my $i = int(rand($arraylength));
      $password .= $p[$i];
   }
   return $password;
} # sub MakePassword
# end of subroutine

To use the subroutine, you have to provide it with the set of characters from which to generate the password. Optionally, you can also provide it with the minimum and maximum length for the generated password. If you do not provide those numbers, 7 will be assumed for both.

Here is a complete Perl script as an example of using the subroutine (paste the subroutine into place where indicated):

#!/usr/bin/perl
my $characterset = 'abcdefghijklmnopqrstuvwxyz';
my $minimum = 5;
my $maximum = 9;

# Paste subroutine MakePassword() above this line.
my $password = MakePassword($characterset,$minimum,$maximum);
print "Content-type: text/plain\n\n";
print $password;
# end of script

# Paste subroutine MakePassword() above this line. my $password = MakePassword($characterset,$minimum,$maximum); print "Content-type: text/plain\n\n"; print $password; # end of script

The script provides a character set, along with the minimum and maximum length, to the subroutine. The subroutine generates the password and returns it to be stored in the variable $password, which is then printed.

There you have it, easy password generation, in a stand-along program and a subroutine to incorporate into your own scripts.

By: Will Bontrager

Copyright 2002 Bontrager Connection, LLC
http://willmaster.com/possibilities/
subscribe-possibilities@willmaster.com