MySQL Forums
Forum List  »  Perl

validating username and password in db???
Posted by: Naveen Gupta
Date: April 29, 2005 06:41AM

i've been able to establish mysql connectivity to display all the data in in an html page by invoking a perl script in the web server. But tough things ahead. I've been trying uselessly for hours to create a script which takes username and password from the user and validate them with those in mysql table and return a response in either situation but not being able to do it.
my script looks somewhat like----


#!/usr/bin/perl

use CGI;
use DBI;
my $query = new CGI;
print $query->header();
#print $query->start_html(-title=>'LOGIN PAGE');

$db="db";
$host="host";
$user="root";
$password=undef;

if(($query->request_method() eq "POST") && ($query->param("user") ne '') && ($query->param("password") ne ''))
{

$user=$query->param("user");
$password=$query->param("password");
$dbh = DBI->connect("DBI:mysql:database=$db:host=$host", $user, $password) or die "Can't connect to database:$DBI::errstr\n";
$qry = $dbh->prepare("SELECT emp_name, password FROM table where emp_name=$user");
$qry->execute;
@row=$qry->fetchrow_array;
$name=$row[0];
$password=$row[1];

if ($user eq $name && $password eq $pass)
{
print "

Thank You!

";
$dbh->disconnect;
print $query->end_html();
}
else
{
print "<HEAD> Username or Password Incorrect!</HEAD>";
print "Please Try Again";

$dbh->disconnect;
print $query->end_html();
}
}
else
{
#print "Content-type: text/html\n\n";

#print <<EOF;
print "<HTML>";
print "<BODY>";
print "<FORM METHOD='POST' ACTION='login_main.pl'>";

print "

Username:</p>";
print "<input type='text' name='user'>
";

print "

Password:</p>";
print "<input type='password' name='password'>
";
print "<input type='submit' value='submit'>
";
print "</FORM>";
print "</BODY>";
print "</HTML>";
#EOF
#print $query->end_html();
}

not getting the desired output. basically a problem of data validation with db.
Could anyone help me out with this one!!
Thanks a lot
Naveen

Options: ReplyQuote


Subject
Written By
Posted
validating username and password in db???
April 29, 2005 06:41AM
May 02, 2005 01:16AM
May 02, 2005 02:19AM
May 02, 2005 04:08AM
May 02, 2005 06:08AM
May 02, 2005 06:19AM
May 02, 2005 06:36AM
May 02, 2005 07:25AM
May 02, 2005 11:49PM
May 03, 2005 03:58PM
May 04, 2005 04:55AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.