Hello! In the following code verifies a password, passed from an html
page:
#check for proper password
if ($in{'password'} ne "test")
{
I would like to change this so, the code looks at a text file of
usernames and passwords, instead of the hardcoded password "test". The
text file currently exists and is formatted like this:
bob|jane
Jessica|732
Mike|Chevy
I'd appreciate any suggestions as to the best way to approach this.
Thanks, Maureen
Here is a copy of the complete code currently used:
#!/usr/local/bin/perl
require "cgi-lib.pl";
#process incoming form data
&ReadParse;
#set content type
print &PrintHeader;
#initialize variables
$pwfile =
"/data1/hypermart.net/worldwidewebstrategies/datafile/pwdata.txt";
$tmpfile =
"/data1/hypermart.net/worldwidewebstrategies/datafile/pwdata.tmp";
$lokfile =
"/data1/hypermart.net/worldwidewebstrategies/datafile/pwlock.fil";
#Print initial tags for web page
print "<HTML><BODY>\n";
#check for existence of password file
unless (-e $pwfile)
{
#password file doesn't exist!
#print message & shut down
print <<"PrintTag";
<H1>Sorry!</H1>
<P>$pwfile has't been uploaded to the
proper directory. Please contact the webmaster.</P>
</BODY>
</HTML>
PrintTag
exit(0);
}
#check for blank form fields
if ($in{'password'}eq"" ||
$in{'winery'}eq"" || $in{'wine'}eq"" || $in{'price'}eq"")
{
#set content type
}
#check for proper password
if ($in{'password'} ne "test")
{
#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.
</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{'year'}|$in{'winery'}|$in{'wine'}|$in{'price'}\n";
close(FILE);
#close lock file
close(LOCK_FILE);
#delete lock file
unlink("lock.fil");
#print database contents
print "Location:http://worldwidewebstrategies.com\n\n";
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]