Guest_imported
New member
- Jan 1, 1970
- 0
The following script should take the username and the password from the form and match it with the database. If the user exists then he can continue, otherwise he has to register. The thing is that although everything seems correct, it does not work! Could anyone tell me what's wrong? :-(
#!/usr/bin/perl
'usr/pub/prepare postgr';
use CGI;
use DBI;
$|=1;
print "Content-type: text/html\n\n";
#Get input from the web
if ($ENV{'REQUEST_METHOD'} eq "POST" {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{'QUERY_STRING'};
}
@pairs= split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack ("C", hex($1))/eg;
$contents{$name} = $value;
}
$regexp = "[\<\>\|\;\,\']";
$mname = $contents{'username'};
$mname =~ s/$regexp//g; #remove suspect chars
$mpwd = $contents{'password'};
$mpwd =~ s/$regexp//g; #remove suspect chars
#opens database
my ($dbh, $sth, $z);
$dbtype = "Pg";
$database= "xxxx";
$dbserver= "xxxxxxx";
$dbport= 5432;
$data_source = "dbi:$dbtype:dbname=$database;host=$dbserver;port=$dbport";
$dbh = DBI->connect("$data_source", "", ""
$z = "select username, password from supervisor where (($mname='username') and ($mpwd='password'))";
$sth = $dbh->prepare($z);
$sth->execute();
while (@row=$sth->fetchrow_array())
{
$html=$html."@row";
}
$sth->finish();
$dbh->disconnect;
if ($html eq " "
{
print <<"HTMLHEAD";
<HTML>
<HEAD>
<TITLE>WRONG!</TITLE>
</HEAD>
<BODY>
<P>
<CENTER>
<A HREF="<P>
</BODY>
</HTML>
HTMLHEAD
}
else
{
print <<"HTMLHEAD";
<HTML>
<HEAD>
<TITLE>RIGHT PASSWORD AND USERNAME</TITLE>
</HEAD>
<BODY>
<h2><center>You have successfully logged in!</center></h2>
<h2><center>Click on the link to enter..</center></h2>
<CENTER>
<A HREF="</CENTER>
</BODY>
</HTML>
HTMLHEAD
}
#!/usr/bin/perl
'usr/pub/prepare postgr';
use CGI;
use DBI;
$|=1;
print "Content-type: text/html\n\n";
#Get input from the web
if ($ENV{'REQUEST_METHOD'} eq "POST" {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{'QUERY_STRING'};
}
@pairs= split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack ("C", hex($1))/eg;
$contents{$name} = $value;
}
$regexp = "[\<\>\|\;\,\']";
$mname = $contents{'username'};
$mname =~ s/$regexp//g; #remove suspect chars
$mpwd = $contents{'password'};
$mpwd =~ s/$regexp//g; #remove suspect chars
#opens database
my ($dbh, $sth, $z);
$dbtype = "Pg";
$database= "xxxx";
$dbserver= "xxxxxxx";
$dbport= 5432;
$data_source = "dbi:$dbtype:dbname=$database;host=$dbserver;port=$dbport";
$dbh = DBI->connect("$data_source", "", ""
$z = "select username, password from supervisor where (($mname='username') and ($mpwd='password'))";
$sth = $dbh->prepare($z);
$sth->execute();
while (@row=$sth->fetchrow_array())
{
$html=$html."@row";
}
$sth->finish();
$dbh->disconnect;
if ($html eq " "
{
print <<"HTMLHEAD";
<HTML>
<HEAD>
<TITLE>WRONG!</TITLE>
</HEAD>
<BODY>
<P>
<CENTER>
<A HREF="<P>
</BODY>
</HTML>
HTMLHEAD
}
else
{
print <<"HTMLHEAD";
<HTML>
<HEAD>
<TITLE>RIGHT PASSWORD AND USERNAME</TITLE>
</HEAD>
<BODY>
<h2><center>You have successfully logged in!</center></h2>
<h2><center>Click on the link to enter..</center></h2>
<CENTER>
<A HREF="</CENTER>
</BODY>
</HTML>
HTMLHEAD
}