MySQL MD5() Problem

Alles, was MariaDB und MySQL betrifft, kann hier besprochen werden.

MySQL MD5() Problem

Postby edwa5823 » 24. May 2008 03:02

I seem to have a problem getting MySQL to compare strings correctly using the MySQL MD5() function. Here is an example:

I have a table 'users' with two fields (among others) 'username' and 'password'. In this example the username is 'tester' and the password is '098f6bcd4621d373cade4e832627b4f6' (test).

This code fails:
Code: Select all
SELECT * FROM users WHERE username='test' AND password=MD5('test');


This code succeeds:
Code: Select all
SELECT * FROM users WHERE username='test' AND password='098f6bcd4621d373cade4e832627b4f6';


I have tried this every which way and two hours later it I have to assume that this is a XAMPP issue. If anyone has any insight PLEASE let me know.

Thanks in advance.
edwa5823
 
Posts: 2
Joined: 24. May 2008 02:55

Postby logout » 25. May 2008 12:28

The Query sees the "MD5('test')" as the password and not the md5-Encryptet string.

Try this:

Code: Select all
$sql = "SELECT * FROM `users` WHERE `username` = 'test' AND `password` = '".md5('test')."'";
$result = mysql_query($sql);


Now it has to work.
logout
 
Posts: 33
Joined: 01. January 2008 04:13

Postby edwa5823 » 27. May 2008 20:49

I am sure that will work, it would be using the php MD5() function to encrypt the password. The point that I am making is that MySQL has an embedded function MD5() that will encrypt it when mysql runs. It works just fine on my actual live Apache server but the Xampp installation fails. I just found it odd since it is running the same software in essence.
edwa5823
 
Posts: 2
Joined: 24. May 2008 02:55

Postby pt » 30. May 2008 08:07

I have the same problem between different xampp versions.

I have inserted the SQL datas from one database to another of a different pc. Surprise, the password was invalid.

I suspect the cause is the SQL codes/character sets (a.e. UTF-8 Unicode)...
pt
 
Posts: 4
Joined: 04. May 2008 11:00
Location: Adendorf


Return to MariaDB - MySQL

Who is online

Users browsing this forum: No registered users and 32 guests