batkins has asked for the wisdom of the Perl Monks concerning the following question:
Here's the code I use to authenticate a user:
Basically it just authenticates the user and if the authentication is successful, the username is saved in $cur_user. The return value of the sub is an anonymous array suitable for passing to CGI::header. The code definitely authenticates properly because I can log in. It's the saving of the cookie that causes the problem. The code that actually prints the header is:sub authenticate { my ($user, $pass); if($query->param("user")) { $user = $query->param("user"); $pass = md5_hex($query->param("pass")); } elsif($query->cookie("lyr_bat")) { ($user, $pass) = split /-/, $query->cookie('lyr_bat'); } if($user and $pass) { my $users = $conn->query("SELECT * FROM lyr_users WHERE user = + ?", $user); if($pass eq $users->field("pass")) { $users->field("last_logon", time); $users->update("id"); $cur_user = $user; return $query->cookie(-name => 'lyr_bat', -value => "$user +-" . $users->field("pass"), -expires => '+10m', -path => '/') unless +$query->param("node") eq "logout"; } } if($query->param("node") eq "logout") { if($user) { my $users = $conn->query("SELECT * FROM lyr_users WHERE u +ser = ?", $user); $users->field("last_logon", 0); $users->update("id"); } $cur_user = undef; return $query->cookie(-name => 'lyr_bat', -value => ''); } return []; }
I'm at a loss here. I'd appreciate any help. BTW, I've tried removing the -path and -expires section: no dice.my $cookie = authenticate(); print $query->header(-cookie => $cookie);
TIA,
Bill
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Weirrd Cookie Problems
by antirice (Priest) on Aug 22, 2003 at 00:52 UTC | |
by batkins (Chaplain) on Aug 22, 2003 at 01:08 UTC | |
by antirice (Priest) on Aug 22, 2003 at 01:28 UTC | |
|
Re: Weirrd Cookie Problems
by cees (Curate) on Aug 22, 2003 at 03:47 UTC |