#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |