This has been asked numerous times here on SO. But I haven’t found a solution for my problem.
I want to create a short hash (let’s say max 8 chars) for an invitation system. I cannot use base[X] encoding because that would be too easy to guess. I cannot just trim extra characters of e.g. an MD5 hash, because I think the problem of collisions will come up at some time then.
Is there a solution for this?
If you want to be assured of never having a collision, your best bet is to maintain a database of valid hashes and compare against that database when generating new hashes.
If you think you will have a high volume, you may want to pre-generate the hashes so that you have a “haystack” of them ready to use. Some people do this with random numbers because hardware random number generators can only produce numbers at a certain rate.