Hello! I hope someone can help me.  

I am working on the following code, written to accomplish these tasks:

1)Accept username and password from an HTML page
2)Open a text file and store the username and passwords listed there in
an array
3)Compare the username and password in the array to the username and
password entered on the HTML page.
4)If username and password match, direct the user to another web page.
5) If username and password do not match or fields are left blank on the
HTML form, direct user to an error page.

Currently, the array seems to only be picking up the last name listed in
the text file.  

Would you please take a look at my code to help me see what I have done
wrong?

Thanks, Maureen

#!/usr/local/bin/perl  
require "cgi-lib.pl"; 
#process incoming form data  
&ReadParse; 
#open the database in read-only mode  
open(FILE,"pwdata.txt") || die "Can't find database\n"; 
#store database contents in an array and close file  
@indata = <FILE>;  
close(FILE); 
foreach $i (@indata)   
{ 
#remove hard return character from each record  
chomp($i); 
#split fields on pipe character   
#assign a variable name to each of the fields  
($username,$password) = split(/\|/,$i);
} 
#check for blank form fields  
if ($in{'username'}eq"" || $in{'password'}eq"")  
{ 
#set content type 
} 

#check for proper password  
if ($username!=~/$in{'username'}/) 
{ 
#invalid password--create error message and exit  
print &PrintHeader; 
print <<"PrintTag";  
<HTML>  
<HEAD>  
<TITLE>Error!</TITLE>  
</HEAD>  
<BODY BGCOLOR="white" TEXT="black">  
<H1>Authorization Required</H1>  
<BLOCKQUOTE>  
You do not have authorization to enter this website. Please click <a
href="http://www.worldwidewebstrategies.com";>here</a>
to return to the WWWS web site.
</BLOCKQUOTE> 
<BLOCKQUOTE>  
If you feel you have received this message in error, please return to
the
login screen and try to enter your username and password again.  
 </BLOCKQUOTE>  
</BODY>  
</HTML>  
PrintTag
exit(0);  
} 

#check for existence of lock file  
if (-e "lock.fil")   
{ 
#lock file exists! print message & shut down   
print &PrintHeader;
print <<"PrintTag";
<HTML>  
<HEAD>  
<TITLE>File in use</TITLE>  
</HEAD>  
<BODY BGCOLOR="white" TEXT="black">  
<H1>Try again!</H1>  
<BLOCKQUOTE>  
The database is in use. Please try again later.  
</BLOCKQUOTE>  
</BODY>  
</HTML>  
PrintTag
exit(0);
} 
#everything is okay. Create lock file.  
open(LOCK_FILE, ">lock.fil"); 
#open, append record, and close database  
open(FILE,">>data.txt") || die "Can't find database\n";  
print FILE
"$in{'username'}|$in{'password'}\n";
close(FILE); 
#close lock file  
close(LOCK_FILE); 
#delete lock file  
unlink("lock.fil");
#print database contents  
print "Location:http://www.worldwidewebstrategies.com\n\n";;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to