use strict; use Digest::SHA1; my $plaintext="Test1ng"; #generate a two char salt... my $salts= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; my $s1 = rand(64); my $s2 = rand(64); my $salt = substr($salts,$s1,1) . substr($salts,$s2,1); my $sha1 = Digest::SHA1->new; $sha1->add($salt.$plaintext); # the enc pass is presented with the plaintext salt as the first two chars. my $encpass = $salt. $sha1->hexdigest; print "$encpass\n"; This outputs: kcc68a68507e8636a1a9a6badc059342b19a12c58e And to test the password: use strict; use Digest::SHA1; my $storedpass='kcc68a68507e8636a1a9a6badc059342b19a12c58e'; my $plaintext="Test1ng"; #pull salt from the saved password so you can compair... my $salt = substr($storedpass,0,2) ; my $sha1 = Digest::SHA1->new; $sha1->add($salt.$plaintext); # the enc pass is presented with the plain-text salt as the first two chars. my $encpass = $salt. $sha1->hexdigest; print "if $encpass = $storedpass the password is correct...\n"; which outputs: perl testpass.pl if kcc68a68507e8636a1a9a6badc059342b19a12c58e = kcc68a68507e8636a1a9a6badc059342b19a12c58e the password is correct...