I'm using the following code for a cookie-based login. The script has no syntax error, but it is not able to send the cookie to the user's browser. In IE, it's processing for over 2 mins and then I get a timeout error.
Any help would be greatly appreciated.
I'm using CGI 2.98 w/ Perl 5.6.1 on a Win Platform.
Thank you in advance
Code:
#!/usr/local/bin/perl
use CGI;
$cgi = new CGI;
# Verify if user submitted login information
if ($cgi->param('cmd') eq "validate_login") {
# Verify Username & Password (Release Cookie)
$username = $cgi->param('user');
$password = $cgi->param('pass');
chomp($username);
chomp($password);
# Open Users List
open FILE, "user.txt";
while () {
# Split Users List
($u,$p) = split /:/, $_;
# Delete trailing
chomp($p);
chomp($u);
# Validate User Information
if ($u eq $username) {
if ($p eq $password) { $valid=1;
}
}
}
close FILE;
if ($valid) {
# Generate Cookie
$cookie = $cgi->cookie(-name=>"login", -value=>$username, expires=>'+10M');
# Send Cookie
print $cgi->header(-type=>"text/html", -cookie=>$cookie);
print "Hi $username";
print $cookie;
}
else {
print $cgi->header();
print "Invalid Username or Password";
}
}
else {
print $cgi->header();
# Read user cookie
$username = $cgi->cookie("login");
# Verify if cookie exists
if ($username) {
# Valid Cookie
print "Hi $username! You have been automatically logged in!!";
}
else {
# No coookie found
print $cgi->header();
print "
<HTML>
<BODY>
<FORM method='POST' action='".$cgi->url()."'>
<INPUT type='hidden' name='cmd' value='validate_login'>
Username:
<INPUT type='text' name='user'>
Password:
<INPUT type='text' name='pass'>
<INPUT type='submit'>
</FORM>
</BODY>
</HTML>";
}
}
1;