ullmark/hashids.net

Document the effective character limit of the salt

aradalvand opened this issue · 5 comments

Basically this issue but for this library.
In short, salts seem to have a 24 character limit, anything beyond that doesn't actually affect the result. This should ideally be mentioned in the README.

Do you want to make a PR for the documentation and add a test to confirm?

Actually, upon further testing I found out it's not 24 characters, it has to do with the length of the alphabet which I think you've already alluded to in the "Features" section of the README:

Allows custom alphabet as well as salt — so ids are unique only to you. (salt must be smaller than alphabet)

Although one might argue this isn't precise enough, because it's not exactly alphabet - 1, for a 36-character alphabet, for instance, (0-9 + A-Z) it seems like the salt limit is 24, for a 51-character alphabet, the limit seems to be 36.

I'm not sure what the formula is exactly 🤔

It's the alphabet - 1 - separators.

The separators are characters used to denote the different integers combined into a single ID. There's a default list of 14 characters, with 7 letters in both lower and uppercase. If these occur in the alphabet then they're removed from the available characters.

If you only pass in a lowercase alphabet then it'll remove those 7 lowercase characters, otherwise it'll remove all 14.

https://github.com/ullmark/hashids.net/blob/master/src/Hashids.net/Hashids.cs#L72

Oh okay, good to know.
I think it'd be helpful to mention this in the README.

Readme has been updated with notes on config and usage.