A
A
Alexander2014-05-18 16:12:12
PHP
Alexander, 2014-05-18 16:12:12

How unique is the hash part (md5)?

Greetings!
The project has a "client-supplier" dialog interface.
To identify the dialog, I use the first 6 characters from the md5 hash of the strings (client_email + product_id).
Example: site.com/sms/367a46 Tell me
if this is a normal path?
What is the probability of matching this part of the hash for other combinations of "client_id+email"?
Thank you.
PS Why only 6 characters? I need brevity - because I send these links using SMS messages.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir Mochulsky, 2018-03-16
@librown

Dude, don't ever do that. Never!
All hashes have a collision, simply because they are hashes. And they are needed only to check the equality of the input data with a certain probability, without comparing the entire input data.
If you need an order number or some other UID, generate them however you want, at least +1, at least with a hash. But if you please, check for 100% that this is no longer in your database / table, that is, in the place where they should be unique.
This is the only sane way to get 100% done and not with a barricade of crutches. We are not soothsayers to hope and believe, we are engineers and programmers.

S
Sergey, 2014-05-18
Protko @Fesor

Well... as though collisions and for normal md5 can be.
As for brevity, you can also transfer the md5 hash from the hexadecimal system to a system with a large set of characters, thereby reducing the number of characters, this can reduce the chances of getting into a collision.
In general, there are shorter hashes, you can use them. But collisions vseravno can be.

R
Rsa97, 2014-05-18
@Rsa97

Well, the total number of options in such a hash is 2 24 . This means that with a probability of 1/2 among approximately 5000 randomly selected values ​​there will be the same. The birthday paradox , however.

A
Alexander, 2014-05-18
@librown

I decided to do this:
hash ( 'crc32b' , md5( $client_email . $id ) );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question