I'm learning perl, and I'm currently trying to write a user login system. I have the following code in login.pl:
# !perl use CGI qw(:standard); # use the CGI libraries print header; # start the html output $username = param('username'); # take <input name=username> $password = param('password'); # take <input name=password> + open(FILE, "./users/$username"); # open the user's file in $use +rs $passhash = <FILE>; # read the password hash from the f +ile close(FILE); # close the file if (crypt($password, $passhash) eq $passhash) { print "You are now logged in."; } else { print "Incorrect username or password, please try again."; }
$passhash was written to a file with the user's name earlier on (in newuser.pl):
$salt = join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z') [rand 64, rand 6 +4]; # create random two-character salt $passhash = crypt($password, $salt); # hash the password with t +he salt
My question is: how can I set it so that the user can stay logged in between pages (eg. use a cookie) without storing the password somewhere in plaintext to check $passhash against? Sorry if I've gone about this whole thing completely the wrong way.

In reply to setting a cookie on login by reklaw

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.