I agree with
hardburn.
What I use is taken from Lincoln Stein's
Apache Modules book.
I create a string which is passed to the cookie and is also saved in a database for comparison.
It might be overkill but the cookie string is updated on each page as one of the fields used to create it is a timestamp. As Lincoln points out this is extremely sensitive to the smallest change in passed parameters, therefore is very hard to spoof and (almost) insures randomness.
use MD5;
my $MAC = MD5->hexhash( $secret.
MD5->hexhash(join '', $secret, @fields)
);
The
$secret variable holds a 128 character string, which should be as random as possible.
The
@fields array holds whatever data you want to use, as stated before preferably not relevant user data, which combination should of course be unique for each session.
Changing the
$secret string on a regular basis will also provide peace of mind ;-)
Update
use MD5;
my $MAC = MD5->hexhash( $secret.
MD5->hexhash(join ':', $secret, @fields)
);
It looks like the book had a typo as this correct version of the code appears somewhere else in the book.
Sorry Lincoln, my bad!
jayrom
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.