php - Is it possible the MD5 of two different strings be identical? -


i'm trying create dynamic avatar website's users. stackoverflow. have php script generates image based on string:

path/to/avatar.php?hash=string 

i want use md5 of users' emails name of avatars: (and string php script generates image based on)

$email = $_get['email']; $hash  = md5($email); copy("path/to/avatar.php?hash=$hash","path/img/$hash.jpg"); 

now want sure, can use md5 of emails avatar's name? mean isn't there 2 different strings have identical md5's output? in other word want know whether output of 2 different strings unique?

i don't know question clear or not .. want know, there possibility of being duplicate md5 of 2 different emails?

as goal here use hash it's uniqueness rather it's cryptographic strength md5 acceptable. although still wouldn't recommend it.

if settle on using md5, use globally unique id control rather user-supplied email address, along salt.

i.e.

$salt = 'random string'; $hash = md5($salt . $userid); 

however:

  • there still small chance of collision (starting @ 2128 , approaching 264 relatively due birthday paradox). remember chance, hashn , hashn+1 collide.
  • there not reasonable way determine userid hash (i don't consider indexing 128-bit hashes can query them reasonable).

you use stackoverflow example.

user profiles on site like: http://stackoverflow.com/users/2805376/shafizadeh

so wrong having avatar urls http://your_site/users/2805376/avatar.png ? end storage /path/to/images/002/805/376.png

this guarantees unique name, , provides simple , easy work way of storing, locating, , reversing id assigned images user.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -