Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl - Cookie Login

Status
Not open for further replies.

Alphabin

Programmer
Dec 8, 2002
119
CA


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;
 
while (<FILE>) in Open Users List might be it

--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ... smack the fecker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top