Computing.Net > Forums > Programming > Validating md5 password in perl?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Validating md5 password in perl?

Reply to Message Icon

Name: Naveen
Date: April 30, 2005 at 01:02:48 Pacific
OS: Win xp
CPU/Ram: p4 512
Comment:

hi all,
A perl code that wont work.When i'm typing the username and password in an html page-- which is being validated with mysql, i'm being shown "Username or Password Incorrect!" which should not be the case. Instead i shud get a "Thank You" message. A couple of guys told me to include a code to md5 the password i'm entering in the textbox, and then match it with the encrypted password (which also has to be fetched using some particular code). Only then i'll be able to authenticate.
And i dont have access to MYsql client on a terminal window. i can access it through a web interface. I can see the table structure there which shows the passwords as encrypted.
My code looks as follows --

#!/usr/bin/perl

use CGI;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use DBI;

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

$db="database";
$host="host";
$user="user";
$password=pwd;

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

$chkuser=$query->param("user");
$chkpassword=$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 new_user where emp_name=$chkuser");
$qry->execute;

@row=$qry->fetchrow_array;

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

if ($chkuser eq $name && $chkpassword eq $password)
{
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();
}

If anyone could help me out of this one..it would be great
Thank You
naveen



Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: April 30, 2005 at 05:02:04 Pacific
Reply:

If the passwords have been md5 hashed (not encrypted) before being placed in the records then obviously they won't match the text passwords. You can either put a note on the web page form asking the users to calculate the md5sum of their passwords and enter that in the password field ;-) or write code to compare the db entry against an md5sum of what the user enters in the password field. If you have access to a *nix system, 'man Digest::MD5'


0

Response Number 2
Name: FishMonger
Date: April 30, 2005 at 09:16:20 Pacific
Reply:

See my post in the other thread of yours reguarding this issue.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


java file data stamp Shared memory in C



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Validating md5 password in perl?

How to write html code in perl? www.computing.net/answers/programming/how-to-write-html-code-in-perl/12668.html

How to display next page in perl? www.computing.net/answers/programming/how-to-display-next-page-in-perl/12685.html

Password in connection string on VB www.computing.net/answers/programming/password-in-connection-string-on-vb/484.html