Hi, am trying to let a user enter their name and a password to be stored into a file, then check to see if the password entered is equal to a password stored in a file called password. When the passwords are equal the user can delete the message posted. This is my code. any help please
#!/usr/bin/perl -w
use warnings;
use Fcntl;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
print "Content-type:text/html\r\n\r\n";
my @name;
my @hold;
my $saved_pass;
my $j = 0;
my $temp = 0;
my $holder;
my $user_pass;
local ($buffer, @pairs, $pair, $name, $value, %FORM);
# Read in text
$ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
if ($ENV{'REQUEST_METHOD'} eq "POST")
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}else {
$buffer = $ENV{'QUERY_STRING'};
}
# Split information into name/value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%(..)/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
open INPUT,"< password";
my @lines =<INPUT>;
close INPUT;
print $lines[-1];
$saved_pass = $lines[-1];
open (FILE,"+>>checkp.txt");
seek FILE, 0, 0;
while(<FILE>){
chomp;
$name[$j] = $_;
$j++;
}
close(FILE);
if($FORM{prev}){
open INPUT,"+< d";
my @lines =<INPUT>;
close INPUT;
print $lines[-1];
$holder = $lines[-1] - 1;
open (MFILE, '>> d');# or die("Cannot Open File");
print MFILE $holder,"\n";
close (MFILE);
#$holder = 5;
$temp = $holder;
}
if($FORM{nxt}){
open INPUT,"+< d";
my @lines =<INPUT>;
close INPUT;
print $lines[-1];
$holder = 1 + $lines[-1];
open (MFILE, '>> d') ;#|| die("Cannot Open File");
print MFILE $holder,"\n";
close (MFILE);
$temp = $holder;
}
if($FORM{delet}){
open INPUT,"+< d";
delete $names[$temp];#$lines[-1];
close INPUT;
open (MFILE, '>> d') ;#|| die("Cannot Open File");
print MFILE $holder,"\n";
close (MFILE);
$temp = $holder;
}
$first_name = $FORM{firstname};
$user_pass = $FORM{upass};
$text_content = $FORM{textcontent};
$Delete = $FORM{delet};
########################################################################
#writting user data to a file
########################################################################
if((!($FORM{prev} || $FORM{nxt})) && ($FORM{firstname} )){
open (MYFILE, "+>> checkp.txt") ;#|| die("Cannot Open File");
print MYFILE $first_name,"\t";
print MYFILE $user_pass,"\t\t";
print MYFILE $text_content,"\n";
close (MYFILE);
}
my $password = "cgi";
#######################################################################
#print "Content-type:text/html\r\n\r\n";
#print "saved_pass ",$saved_pass,"\n";
print "<html>";
print "<div align=center>";
print "Message Board";
print "<div align = left>";
print "<form action=\"/cgi-bin/exercise194.cgi\" method=\"POST\">";
print "<br><br><br>Please enter your full name<br><br>";
print "Name: <input type=\"text\" name=\"firstname\"> <br>";
print "Password: <input type=\"text\" name=\"upass\"> <br>";
print "<textarea name=\"textcontent\" align=left cols=40 rows=4>";
print "</textarea><br>";
print "<input type=\"submit\" value=\"Submit\"><br><br>";
print "<input type=\"submit\" value=\"prev\" name=\"prev\">";
print "<input type=\"submit\" name=\"nxt\" value=\"next\"><br><br>";
print "<input type=\"submit\" name=\"delete\" value=\"delete\">";
print "</form>";
print "</html>";
if(!($FORM{firstname} ) && ($FORM{prev} || $FORM{nxt})){
print "<html>";
print "<div align = left>";
print "<form action=\"/cgi-bin/exercise194.cgi\" method=\"POST\" target=\"_blank\">";
print "<head>";
print "<title>output</title>";
print "</head>";
print "<body>";
print "<left>";
print "</body>";
print "</html>";
}
if($FORM{prev} ){
if(($password == $FORM{upass}) && ($FORM{firstname})){
print "<html>";
print "<div align = left>";
print "<form action=\"/cgi-bin/exercise194.cgi\" method=\"POST\" target=\"_blank\">";
print "<head>";
print "<title>output</title>";
print "</head>";
print "<body>";
print "Previous entry :$temp $name[$temp]";
print "Password : $user_pass";
print "</body>";
print "</html>";
}else{
print "<html>";
print "<div align = left>";
print "<form action=\"/cgi-bin/exercise194.cgi\" method=\"POST\" target=\"_blank\">";
print "<head>";
print "<title>output</title>";
print "</head>";
print "<body>";
print "Previous entry :$temp $name[$temp]";
print ", no password entered!";
print "</body>";
print "</html>";
}
}
if($FORM{nxt}){
if(($password == $FORM{upass}) && ($FORM{firstname} )){
print "<html>";
print "<div align = left>";
print "<form action=\"/cgi-bin/exercise194.cgi\" method=\"POST\" target=\"_blank\">";
print "<head>";
print "<title>output</title>";
print "</head>";
print "<body>";
print "Next entry :$temp $name[$temp]";
print "Password : $user_pass";
print ", password correct you may delete message!";
#print "<input type=\"submit\" value=\"delete\"><br><br>";
print "</body>";
print "</html>";
}else{
print "<html>";
print "<div align = left>";
print "<form action=\"/cgi-bin/exercise194.cgi\" method=\"POST\" target=\"_blank\">";
print "<head>";
print "<title>output</title>";
print "</head>";
print "<body>";
print "Next entry :$temp $name[$temp]";
print ", no password was entered!";
print "</body>";
print "</html>";
}
}
if($FORM{delet}){
print "<html>";
print "<div align = left>";
print "<form action=\"/cgi-bin/exercise194.cgi\" method=\"POST\" target=\"_blank\">";
print "<head>";
print "<title>output</title>";
print "</head>";
print "<body>";
print "Message deleted!";
print "</body>";
print "</html>";
}
if((!($FORM{prev} || $FORM{nxt})) && ($FORM{firstname} )){
print "<html>";
print "<div align = left>";
print "<form action=\"/cgi-bin/exercise194.cgi\" method=\"POST\" target=\"_blank\">";
print "<head>";
print "<title>output</title>";
print "</head>";
print "<body>";
print "<left>";
print " 1 Message Posted.";
print "</body>";
print "</html>";
}
1;