in reply to Re: Crypt::CBC and verifying passwords
in thread Crypt::CBC and verifying passwords

I had this same problem with blowfish and ended up needing to encrypt everything in the same file. The easiest way to do this was to create a module with two subs that handle encryption and comparision. I offer this untested code, which will hopefully point you in the right direction. Note I have not done any taint checking or etc. so this if very unsecure code, I'm also not saying this is a good idea just that it will work.

package encryptstuffmodule; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); use Crypt::Blowfish; $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = (); @EXPORT_OK = qw(&encryptforauthorize &encryptnew); %EXPORT_TAGS = (DEFAULT => [qw(&encryptforauthorize)], AddNewEncrypt => [qw(&encryptnew)]); sub encryptnew { my $encryptme = sprintf("%08d", $_[0]); my $fileforpass = "/foo/bar/baz/.passwords"; #a database is proably +better but I will use a file for example my $salt = pack("H16", "hf73mkf6vbf559"); my $encrypted = $cipher->encrypt($encryptme); open (TESTFILE, ">>$fileforpass") || die "TESTFILE cannot open"; print TESTFILE $encrypted, "\n"; return 1; } sub encryptforauthorize { my $fileforpass = "/foo/bar/baz/.passwords"; my $salt = pack("H16", "hf73mkf6vbf559"); my $cipher = new Crypt::Blowfish $salt; my $forcompare = $cipher->encrypt(sprintf("%08s", $_[0])); open (TESTFILE, $fileforpass) || die "File cannot open"; while (<TESTFILE>) { chomp; return "okay" if $forcompare eq $_; } return "bad"; } 1;

"Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce