Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could md5 hash of a string be different one place to another? [duplicate]

Tags:

php

hash

md5

Possible Duplicate:
Will the MD5 cryptographic hash function output be same in all programming languages?

Hi,

I have a problem about md5 hashing. Users can upload profile picures on my project. I am md5 hashing usernames for profile picture name. But there is something interesting. I am hashing a value both with a test page on my server and md5 encrypt websites with same result. When I use this encryption for renaming image, it produces something different. It produces different value on image manipulation file.

Do you have any idea?

This is my check script:

<?php echo md5('funky'); ?>

It produces below code on my server and also on md5encrypter.com :

6b818a3a6bf1234ed24c940021922b63

But it produces on my image manipulation file below code. I dont know what it is:

d41d8cd98f00b204e9800998ecf8427e

Script for sql query. $userId comes from logged in userId:

$sql = mysql_query("SELECT username FROM users WHERE userId='$userId'");
while($row=mysql_fetch_assoc($sql)){
  $username=$row['username'];
}
like image 675
aiternal Avatar asked Dec 29 '22 03:12

aiternal


2 Answers

d41d8cd98f00b204e9800998ecf8427e is the MD5 hash of an empty string, so somewhere you have failed to fill your string with something more useful...

MD5 will always produce the same output for a given input, otherwise it's not MD5. What I did was simply google for the hash you got, and it turned up a lot of hits. If I didn't get a hit, I would have searched some of the reverse MD5 dictionaries which are around to see if that gave some clues.

As luck would have it, your hash is simply the result of MD5(''), is very common. It clearly indicates you tried to obtain something from your DB, failed, and hashed it anyway.

like image 119
Paul Dixon Avatar answered Jan 30 '23 22:01

Paul Dixon


make 100% sure you are standardizing the input data everywhere as in $enc_md5=md5(trim(strtolower($filename)));

Often unintended whitespace or capitalization result in different MD5 hashes for what was assumed to be identical data.

like image 43
FatherStorm Avatar answered Jan 30 '23 23:01

FatherStorm