1. Home
  2. Computing & Technology
  3. Perl

Perl Module Crypt::GeneratePassword
How to generate a password in Perl with the Crypt::GeneratePassword Perl module.

From About.com

We've already seen a simplistic but somewhat insecure way to generate random passwords in Perl. Luckily there are several Perl modules that can do the same job even better. Let's look at Crypt::GeneratePassword, one such Perl module written by Jörg Walter.

First, like all non-standard Perl modules, you will need to install Crypt::GeneratePassword from CPAN, and then you can include it at the top of your Perl programs with the use statement:

use Crypt::GeneratePassword qw(word);
You can then use the word function in your program:
$password = word(MINIMUM-LENGTH, MAXIMUM-LENGTH);
Here is a sample program that will print a 12 character random readable password:
#!/usr/bin/perl -w
use Crypt::GeneratePassword qw(word);
$word = word(12, 12);
print "$word\n";
exit;
As an alternative, you can also create passwords that are much less readable, but contain more complex characters:
#!/usr/bin/perl -w
use Crypt::GeneratePassword qw(chars);
$word = chars(12, 12);
print "$word\n";
exit;
More Perl Quick Tips
Explore Perl
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Perl
  4. Programming Perl
  5. Packages & Modules
  6. Perl Module Crypt::GeneratePassword - How to generate a password in Perl that is simple and readable with the Crypt::GeneratePassword Perl module.

©2009 About.com, a part of The New York Times Company.

All rights reserved.