Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alphabet must contain at least 4 unique characters #20

Closed
bichtv opened this issue Feb 21, 2017 · 9 comments
Closed

alphabet must contain at least 4 unique characters #20

bichtv opened this issue Feb 21, 2017 · 9 comments

Comments

@bichtv
Copy link

bichtv commented Feb 21, 2017

I have issue:
var hashids = new Hashids("This is my salt", minHashLength, "0123456789");

the way resolve exception ?

Thank for support

@ullmark
Copy link
Owner

ullmark commented Feb 21, 2017

I'll have a look and see if I can reproduce!

@ullmark
Copy link
Owner

ullmark commented Feb 21, 2017

what is your variable "minHashLength"?

@ullmark
Copy link
Owner

ullmark commented Feb 21, 2017

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!

@impworks
Copy link

impworks commented Mar 1, 2017

Came across this issue as well. So should it be possible to use Hashids with an alphabet of 10 digits?

@ullmark
Copy link
Owner

ullmark commented Mar 3, 2017

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.

@jd327
Copy link

jd327 commented Mar 3, 2017

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.

@ullmark
Copy link
Owner

ullmark commented Mar 3, 2017

@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!

@jd327
Copy link

jd327 commented Mar 3, 2017

@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.

@matteofabbri
Copy link

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));

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants