MySQL Forums
Forum List  »  Perl

Re: validating username and password in db???
Posted by: Naveen Gupta
Date: April 30, 2005 02:59AM

hi nick,
thanx a lot for the reply. But i tried ur code and it also didn't work. On clicking the submit button, its showing "Incorrect username or password..PLease Try again!". I don't know wts the reason!! i hope i'm not wrong at any other part of the code, maybe any function or html! if u could just go through it and check (i'm just 2 days old at perl !!)...
its like --

#!/usr/bin/perl

use CGI;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use DBI;
use Digest::MD5 qw(md5 md5_hex md5_base64);

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

$db="database";
$host="host";
$user="ruser";
$password=undef;

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

$chkuser=$query->param("user");
$chkpassword=$query->param("password");
$md5password = md5($chkpassword);

$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 new_user where emp_name=$chkuser");
$qry->execute;

@row=$qry->fetchrow_array;

$name=$row[0];
$password=$row[1];

if (($chkuser eq $name) && ($md5password eq $password))
{
print "<p> Thank You!<p>";
$dbh->disconnect;
print $query->end_html();
}
else
{
print "<HEAD> Username or Password Incorrect!</HEAD>";
print "<a href='login_main.pl'>Please Try Again</a>";

$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 "<p>Username:</p>";
print "<input type='text' name='user'><br>";

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

Thanks a lot once again
Naveen

Options: ReplyQuote


Subject
Written By
Posted
Re: validating username and password in db???
April 30, 2005 02:59AM
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.