an application that i'm maintaining originally used Crypt:DES to 'encrypt' passwords for storage in a cookie to maintain a logged-in user. the app has decided to break with passwords longer than 8 bytes ( which i found out is a limitation of Crypt::DES -- it only handles 8-byte data ).

today I'm working on replacing the Crypt::DES with Crypt::CBC to allow for arbitrary-length password strings, but I can't get validation/ verification of the passwords from the cookie.

in the set_cookie routine:

my $cipher = Crypt::CBC->new( {'key' => 'stringie', 'cipher' => 'DES', 'iv' => 'vectory!', 'regenerate_key' => 0, # default true 'padding' => 'space', 'prepend_iv' => 1 } ); my $epassword = $cipher->encrypt_hex($password);
and the new $epassword is tossed into the cookie.

and later ( on subsequent hits to the app, essentially) we check the cookie pass against the DB pass like so:

my $cipher = Crypt::CBC->new( {'key' => 'stringie', 'cipher' => 'DES', 'iv' => 'vectory!', 'regenerate_key' => 0, # default true 'padding' => 'space', 'prepend_iv' => 1 } ); my $dbpwmd5 = $cipher->encrypt_hex($dbpw);
where  $dbpw is just fetched from the DB based on the username ....

and the values don't match. the newly encrypted $dbpw and the value from the cookie, that is.

after reading a couple other nodes ( Crypt::CBC question, Safe symmetric encryption - Crypt::CBC + Crypt::Blowfish? ) a block cipher (like DES) should allow for comparision.


In reply to 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.