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.26k stars 417 forks source link

Some questions about this lib. #162

Closed thiagomoraesp closed 3 years ago

thiagomoraesp commented 3 years ago

Hi guys, i have some questions about this lib, i want do generate some HashIds based on the database ID(that is unique), with this premise i have the following questions:

The hashid would be unique too? There's no chance of a 1 and a 9897 give me the same hashid in some moment? The hashid is case sensitive? The default hashid always has the same lenght? Whats the longe integer id that i can hash with hashid?

Thanks :)

miquelfire commented 3 years ago

1 and 2 are yes

Not sure what you're asking about with 3

For 4, with the requirement of one of bcmath or gmp, in theory there is no limit. The actual limit is based on how fast your CPU is, and how much time you want the PHP script taking up to calculate the hash. At least with gmp, less than 64 is native speeds, and for either of the two extensions, I assume you won't notice a CPU hit until around 256-bit (I'm guessing the margin of error with timing how fast the library is cleared at this size)

vinkla commented 3 years ago

Thanks for helping out @miquelfire! ⭐

thiagomoraesp commented 3 years ago

Thhanks @miquelfire, i have another question, with the dictionary: ABCDEFGHIJKLMNOPQRTSUVXZYK1234567890

I will have 73815 possible combinations, so how can the hashids keep the id unique when i have more than 73815 ids in my database?