homepage Welcome to WebmasterWorld Guest from 54.166.84.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
verfication of password from a file to delete a posted message
Geeklady



 
Msg#: 4292492 posted 3:49 pm on Apr 5, 2011 (gmt 0)
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;

 

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4292492 posted 5:55 pm on Apr 7, 2011 (gmt 0)

What does / doesn't work?

Generally, I suggest you use CGI.pm to read values passed via CGI. Yes, it is a litle overhead, but you won't even notice it on todays' servers.

Also, a few comments in your code would be great. Just add a line like
# open file $user.ext to store comment
when you begin significant actions, so it's clear what your code should do. It might just be a typo or one line that's messing up.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved