#!/usr/bin/perl use strict; use warnings; use CGI; our $q = CGI->new(); our @cookie_jar=(); our $secure_cookie = defined $q->cookie('securecookie') ? $q->cookie('securecookie') : ''; # is a valid cookie set? if ($secure_cookie) { if ( cookie_ok($secure_cookie) ) { show_secure_stuff(); } else { # invalid cookie, so delete and show form push @cookie_jar, $q->cookie( securecookie => '' ) show_form(); } } # have they just completed the form elsif ($q->param('username')) { check_login_combo(); } # first run, so show form else { show_form(); } sub show_form { # display login form here # with fields 'username' and 'password' } sub check_login_combo { # based on username, grab correct crypted password # from db/textfile and store in $stored_cryptpass # do various other error checks and re-present form # if invalid input my $user = $q->param('username'); my $pass = $q->param('password'); if ($stored_cryptpass eq crypt($pass,$stored_cryptpass) { push @cookie_jar, $q->cookie({-name=>'secure_cookie', -value=>"$user:$stored_cryptpass"}); show_secure_stuff(); } else { # bad login show_form(); } } sub cookie_ok { # do similar check on cookie my ($user,$cryptpass) = split ':', $_[0]; # grab stored_cryptpass and check return $cryptpass eq $stored_cryptpass ? 1 : 0; } sub show_secure_stuff { # display secure page here - ensuring you send the cookie print $q->header(-cookie => \@cookie_jar). 'rest of page here'; }

.02

cLive ;-)


In reply to something like this? by cLive ;-)
in thread How do they expect cookies to work (like this)?? by Anonymous Monk

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.