e.g. perl gencrypt.pl password

A simple example of usage of the crypt function

Note that multiple invocations will (usually) produce different encrypted forms for the same password.

#!/usr/bin/perl -w $password = $ARGV[0]; srand(time|$$); $random = "abcdefghijklmnopqrstuvwxyz1234567890"; for (1..2) { $salt .= substr($random,int(rand(36)),1); } $field = crypt ($password, $salt); print $field;

Replies are listed 'Best First'.
RE: crypted form
by ZZamboni (Curate) on Apr 27, 2000 at 17:36 UTC
    A couple of observations:
    • The arguments of srand are not really that random, and quite easy to predict. The documentation for srand suggests using
      srand( (time() ^ ($$ + ($$ << 15)) );
      or simply not using srand, since the default seed now is something better than time().
    • You are not using all the possible characters for the salt. According to the man page for crypt (in Solaris, at least) the salt is chosen from the set (a-zA-Z0-9./). So you would need to use
      $random=join("", 'a'..'z','A'..'Z','0'..'9','.','/');
      or better yet, replace the for loop with:
      @r=('a'..'z','A'..'Z','0'..'9','.','/'); $salt=$r[rand(@r)].$r[rand(@r)];