![]() |
![]() |
|
|
||
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:
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:
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
| ||