Answer the question
In order to leave comments, you need to log in
Can duplicate hashes occur?
Good day!
On the project, for each order, a link of the form site.com/a715caeb is generated so
that users without authorization can get into their accounts using these links.
Why use crc32b? To keep the links as short as possible - for use in SMS mailing.
I generate it like this:
$hash = hash('crc32b', md5($client_email.$id_item));
$client_email - client's email
$id_item - item ID
Is this a good solution, don't you think? Doubts are tormenting whether a situation can arise when the same hash is generated for different emails and products? Or incredible?
Answer the question
In order to leave comments, you need to log in
Most likely you will not have such volumes to stumble upon a collision.
But it's better to play it safe - go through the database in search of the same hash. If available, use a different id. And it is better to make a variant with several salts and specifying the salt in the database during generation. Use salt as often as possible when generating any hashes.
The decision is disgusting. This is already something from a series about Babushkin's archiver.
Well, of course, there will be conflicts.
It's better to leave MD5 (which has a fairly good chance of collisions), but convert it from inefficient base16 to a shorter form. Base64 is quite suitable, since the encoder is in php out of the box. That's just both non-alphanumeric characters there are not suitable for transmission via url - it's better to replace them:
In total, we save 10 characters out of 32. Of course, 22 is worse than 8, but here you have to choose - either a sufficient length, or collisions and no security at all.
If anyone finds out this:
Генерирую так:
$hash = hash('crc32b', md5($client_email.$id_item));
Absolutely NOT normal. Read on the wiki about the "birthday paradox". The collision probability for an absolutely uniform distribution is 1/sqrt(2^32)=1/(2^16)=1/65536. In reality, crc32 does not provide uniform distribution and therefore the probability of a collision will be much greater.
In addition, such a short address will lead to the fact that an attacker will be able to get to other people's orders by simple enumeration.
By counting md5 first, then crc32, you increase the chance of a collision in my opinion . A collision can occur in the md5 function (same values for different inputs), which will immediately lead to a collision on the crc32 output (same values for the same inputs). In addition, a collision may occur in the crc32b function (same output values for two different md5 results). I don't know how the md5 function in php works, but it seems to me that its output has some structure (32 hexadecimal digits), which may increase the chance of a crc32b collision.
Why use crc32b? To keep the links as short as possible - for use in SMS mailing.If I were you, if determinism is needed, I would:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question