I am working with Crypt::CBC and the Blowfish encryption algorithm to encrypt some passwords. However, when I check to see if the person entered the same string twice (for verification), I get an error back stating that the strings do not match, which is obvious when I print the encrypted strings out. I am using the same Crypt::CBC object to encrypt each string, so they are both being encrypted by the same key. The key in question is a hexidecimal string, 16 characters in length.Any ideas here?
#!/opt/perl5/bin/perl -w use strict; use Fcntl qw (:flock); use Term::ReadKey; use Crypt::CBC; my $pass_file="passfile.txt"; my %Mgrs; my $user=shift; if($user eq "KEY"){die"Can't change that!!!!\n";} open(FH,"$pass_file")|| &ERR("Unable to read password file"); flock(FH,LOCK_EX); while(<FH>){ my($mgr,$passwd,$printer) = split /\|/; chomp $printer; $Mgrs{$mgr}=[$passwd,$printer]; } flock(FH,LOCK_UN); close FH; my $ck=$Mgrs{'KEY'}[0]; #debug #print"CK is $ck\n"; if(exists $Mgrs{$user}){ if($Mgrs{$user}[0] eq ""){ &newpass; }else{ & ERR("Incorrect username"); } }else{ & ERR("Non-Existent User"); } sub ERR{ my $msg=shift; print "$msg\n"; die; } sub newpass{ print"Enter new password: "; ReadMode 2; my $p1=<STDIN>; chomp $p1; ReadMode 0; print "\nEnter it again (for verification): "; ReadMode 2; my $p2=<STDIN>; chomp $p2; ReadMode 0; print"\n"; my $crypt=Crypt::CBC->new({'key'=>$ck,'cipher'=>'Blowfish'}); my $d1=$crypt->encrypt_hex($p1); #Debug #print "$d1\n"; my $d2=$crypt->encrypt_hex($p2); #Debug #print "$d2\n"; if($d1 eq $d2){ $Mgrs{$user}[0]= $d1; }else{ &ERR("Non matching passwords."); } }

TStanley
--------
The only thing necessary for the triumph of evil is for good men to do nothing -- Edmund Burke

In reply to Non matching encrypted string by TStanley

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.