vinkla / hashids

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
https://hashids.org/php
MIT License
5.27k stars 417 forks source link

Do Hash Ids have a max length? #134

Closed Modicrumb closed 4 years ago

Modicrumb commented 4 years ago

I know they can be set to have a minimum length but my goal is that no hash id exceeds 16 characters. Is this possible? would truncating the hash id in the case that it exceeds 16 characters be alright collision-wise?

miquelfire commented 4 years ago

I feel the answer is no.

Any reason you need to limit it to 16 characters?

Modicrumb commented 4 years ago

Yeah, I am trying to use this to generate a unique Id I want to define a record by. I'm not even trying to mask the ids, but I do like the idea of having a random generated string rather than the id itself, also my constraint for the string is 16 bytes. This will come in handy if even though the integer I'm encoding is 16 bytes if the generated string isn't. I realize that probably after a very large number is being encoded it might go over 16 bytes but I think the max I care to address is 9223372036854775807. The reason the constraint is 16 bytes is because this is the max an attribute can be for data sending for a certain protocol. People will be sending data to a server and I want that server to be able to find the record based on that data. I hope that was enough information.

Modicrumb commented 4 years ago

I think that most likely if i just test the length of the upper bounds I can find this out so I'm just closing this.