alphabet must contain at least 4 unique characters
bichtv opened this issue · 9 comments
I have issue:
var hashids = new Hashids("This is my salt", minHashLength, "0123456789");
the way resolve exception ?
Thank for support
I'll have a look and see if I can reproduce!
what is your variable "minHashLength"?
Ok, I've reproduced the issue, the problem here I guess is that the APi is a bit unclear... The Hashids class relies on having an alphabet and separators. After removing separator characters it should at least be 4 characters left.. But the code checks that a bit weird.
I'll make a new version and close this ticket when fixed!
Came across this issue as well. So should it be possible to use Hashids with an alphabet of 10 digits?
I've seen that they've changed a bit in the javascript library from how it was in the original port. You are able to change the alphabet, but not the seps anymore.
@ivanakimov just want to check with you what the intent is, should you be able to construct a hashids object like above. I don't want to loose compatibility with the other ports.
The latest version of Hashids requires a minimum of 16 characters. The reason for that is the length of separators, which is 14. That way if you give the worst possible alphabet, like cfhistuCFHISTU01
, at the very least the library will have 2 characters to compose ids from.
I'm not sure we were ever providing access to seps
from the outside.
To make the above code work (with just numbers as alphabet), @bichtv you'd have to clone the repo and get rid of that restriction manually.
@ivanakimov maybe you're right. Either the capability of sending in seps
was removed, or I shouldn't have allowed it from the beginning when I created the port.
Maybe I should remove that capability then!
@ullmark yeah, well if somebody modifies it, then ids won't match across other implementations. It's actually a todo for future releases, but currently not supported across libs.
Came here to open the same bug. 16 Chars is fine but please fix the error message
if (this.alphabet.Length < 16)
throw new ArgumentException("alphabet must contain atleast 4 unique characters.", nameof (alphabet));