#!/usr/local/bin/perl
#this line tells the server that your using perl.
print "content-type: text/html\n\n";
# this sends out a greeting, and tells the browser your going to give it html content
my $in;
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$in = $ENV{'QUERY_STRING'};
} else {
$in = <STDIN>;
}
# looks complicated, don't worry about how or why it works, basically it takes the data passed to the form that called the script, and dumps it into a varible ($in)
$in =~ s/\+/ /gi;
$in =~ s/%(..)/pack("c",hex($1))/ge;
#this takes the data and brings it into a more handleable english format (escapes it)
$data_in = split (/&/, $in);
for($i = 0; $i <= $#data_in; $i++)
{
@pairs = split (/=/, $data_in[$i]);
$data{$pairs[0]} = $pairs[1];
}
# this takes all the inputed query string and puts it into an aso array called data, using the form field name as its key
open(AUTH, "$data{userid}.dat");
@userinf = <AUTH>;
close (AUTH);
#we open the users dat file, if it exists we dump the contents into an array, by line.
if($userinf[0])
{
# if the varible $userinf[0] exists (it won't if the file wasn't opened) then we do the stuff inside
if($data{pass} eq $userinf[1])
{
# this checks if the password they sent is the same as the one we have stored for them, if it does we print out a welcome message.
print "congrats you logged in!";
}
else
{
# if they got the password wrong, it isn't the same as the one we have stored for them, we print out something telling them so
print "inncorrect password!";
}
}
else
{
#this is the else for the first if statement (getting confusing now) tells them that they got the username wrong
print "Username not found!";
}