On Sat, May 05, 2001 at 12:02:15PM +0000, cherukuwada subrahmanyam wrote:
: Hi,
: Is there any easy way to generate random string of particluar length.
: The idea is to generate passwords randomly.
: I did it using rand function i.e. generating random number and replacing the 
: number with corresponding alphabet.
: Is there any easy way???
: thanks,

I am a firm believer in crypt().  This is one way encryption that
should do the trick for you.  You can never unencrypt the password but
you can validate a password against it.

Here is a sample program:

  #!/usr/local/bin/perl -l

  my $enc = crypt( 'test',
                   join '',
                        ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64,
                   rand 64]
                 );

  my $pass = 'test';

  print $enc;
  print $pass;

  print "Yes!" if crypt( $pass, $enc );

read:
perldoc -f crypt

  Casey West

-- 
"Airplanes are interesting toys but of no military value."
 -- Marechal Ferdinand Foch, Professor of Strategy, Ecole Superieure
    de Guerre.

Reply via email to