in reply to P@$$w0rd$ in perl?
Sample use for crypt would be as follows. The first function receives the plain-text password and returns the encrypted password string. The second one takes an encrypted password string (as generated by the first function) and a plain-text password, and tell you whether the password is correct. Notice how the salt is stored in the first two bytes of the encrypted password. Also note that crypt only uses the first 8 characters of the password.
sub encrypt_passwd { my $pw=shift; # Seed random number generator. From Camel book p. 223. # This should be outside this function, in the program # initialization, otherwise calls to this function very # close in time will result in the same salt. srand ( time() ^ ($$ + ($$ << 15)) ); my @c=('a'..'z', 'A'..'Z', '0'..'9','.','/'); my $s=$c[rand(@c)].$c[rand(@c)]; return crypt($pw, $s); } sub verify_passwd { my ($epw, $pw)=@_; my $s=substr($epw,0,2); return $epw eq crypt($pw,$s); }
|
|---|