MD5 function in MYSQL Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

MD5 function in MYSQL Help

Post by jurklins »

Hey guys, i am trying to have a php authentication login that check into the database:

Code: Select all

 
$web_username=$_SERVER['PHP_AUTH_USER'];
$web_password=$_SERVER['PHP_AUTH_PW'];
require_once('db-connect.php');
$query="select username,password from users where username like '";
$query1=$web_username."' and password=MD5('".$web_password."')";
$query=$query.$query1;
echo $query."<br/>";
$result=$connection->query($query);
 
from the echo query, this is the result:
select username,password from users where username like 'abcUserName' and password=MD5('abcPassword')


but it doesn't seem to work this way in mysql. Any comments??
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: MD5 function in MYSQL Help

Post by s.dot »

Just md5() the password in PHP.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: MD5 function in MYSQL Help

Post by onion2k »

What do you mean by "it doesn't seem to work this way in mysql"? Your SQL looks ok to me.
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Re: MD5 function in MYSQL Help

Post by jurklins »

it should return 1 row where it didnt.....
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: MD5 function in MYSQL Help

Post by pickle »

Are the passwords hashed in the DB?

The query looks fine, it may not be asking of your DB what you think it is.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: MD5 function in MYSQL Help

Post by Mordred »

1. Use mysql_real_escape_string() on both values.
2. Don't use LIKE, use =
3. What does phpMyAdmin say if you do the same query?
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Re: MD5 function in MYSQL Help

Post by jurklins »

No idea what is going on .. But i drop the table and create it back. It seems to work now. By the way what should be the data type of password? Is varchar or char arite?
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Re: MD5 function in MYSQL Help

Post by jurklins »

ya .. the tutorial that i am following is also using "=" instead of "like" . Why is it bettter though? Never really understand what all these sqlinjection does
Post Reply