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


In reply to Re: Re: Crypt::CBC and verifying passwords by kutsu
in thread Crypt::CBC and verifying passwords by geektron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.