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

Custom curse list / seps #17

Closed
dshivak opened this issue May 14, 2015 · 15 comments · Fixed by #65
Closed

Custom curse list / seps #17

dshivak opened this issue May 14, 2015 · 15 comments · Fixed by #65

Comments

@dshivak
Copy link

dshivak commented May 14, 2015

Can an argument be added to override the default hardcoded sep list of characters, or better yet, do a check against a full custom curse list? The sep list character removal may cause estimates of the number of characters needed to be wrong. A custom curse list would also allow non-English speakers to avoid curses in other languages.

@jd327
Copy link
Collaborator

jd327 commented May 15, 2015

Hi @dshivak, sorry for late response. Yes, I think a custom separator list would be nice to have. A custom curse list might be a bit "too-specific" to implement, but an extra parameter to the constructor to replace the sep list might be just fine.

I'll queue it up for next release.

@ravitejaduvva
Copy link

HI,

I have tried to generate hash for two salts, But for both i have received same hash

Salt 1 :

var hashids = new Hashids("8415", 6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");

var id = hashids.encode(2, 4, 3);
var numbers = hashids.decode(id);

Generated Hash : e2c7fo

Salt 2 :

var hashids = new Hashids("17871", 6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");

var id = hashids.encode(2, 4, 3);
var numbers = hashids.decode(id);

Generated Hash : e2c7fo

image

image

Is there any best way to avoid collisions to generate the hash? Help me on this.

@tmorehouse
Copy link

Hashes are only guaranteed to be unique when the same salt is used. Different salts may generate the same hashid result. The salt is just used to "shuffle" the alphabet in use.

@ravitejaduvva
Copy link

Dear tmorehouse, i have given different different salts,

var hashids = new Hashids("17871", 6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
var hashids = new Hashids("8415", 6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");

Can you tel me what i have to change here?
I want to generate the unique hashes from digit 1 to 10000000 serially, can you help?

@jd327
Copy link
Collaborator

jd327 commented Sep 1, 2015

@raviteja1239, go over the documentation, especially this part: http://hashids.org/#collisions

@tmorehouse has given you exactly the right answer. There is no problem, you just have to use the same salt while you're generating ids.

@ravitejaduvva
Copy link

@ivanakimov @tmorehouse - Working! Thanks for your support.

@ravitejaduvva
Copy link

Hi @ivanakimov @tmorehouse

Now I tried to generate the hashes[6 Character] for numbers 0.5 billion with same salt,
But am able to generate up to 164916223 hashes with six char, and for the number 164916224 i have received 7 character hash.

As per the common scenario 62! means [A-Z,a-z,0-9] 62^6 = almost 57 billion unique values possible.
Can you suggest me any idea to generate 6 character hashes without any collision.

@tmorehouse
Copy link

With a minimum 6 character hash, there are actually only a minimum of 5 characters that are used to encode the value. the first character is a seed value to store the "lottery" value for the sorting, and some characters are used as guard values. So even though you may have 62 characters in your alphabet, you really only have 62 - lottery character - guard characters.

If you would like to ensure that the hash is only 6 characters for that last large number, add additional characters to your alphabet (say add in _, -, etc.) to reduce the resulting hash length.

There is no way to actually force a maximum hash length.

The best idea is to find your largest possible value you want to encode and then determine the maximum length hashid generated. then use this as your string size that you are storing.

@ravitejaduvva
Copy link

Hi @tmorehouse

Can you give and example for this,
"If you would like to ensure that the hash is only 6 characters for that last large number, add additional characters to your alphabet (say add in _, -, etc.) to reduce the resulting hash length."

And is there any chance to give alphanumeric encoding for the hash generation? like 1a,1b,1c...

var hashids = new Hashids("Rav1T3jA", 6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
var id = hashids.encode(1a);
var numbers = hashids.decode(id);

Thanks for your support!

@tmorehouse
Copy link

HashIds only encodes numbers, you cannot encode letters. HashIds does support encoding hex numbers as well (separate encode and decode functions though).

As per my coment about hte alphabet:

var hashids = new Hashids(
    "Rav1T3jA",
    6,
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-~`!@#$%^&*()_+-|{}[]:;/?<>");

would generate shorter hashes (since there are more characters to choose from)

Note that some characters given in the above example may not be URL safe

@ravitejaduvva
Copy link

@tmorehouse

If i give special characters, hash may generate with those chars.
Is there any other way to generate the unique hashes[without collision] in 6 characters?

@tmorehouse
Copy link

Not using the hashid's library.

Maybe you should use BASE64 or BASE62 encoding of your numbers and pad the end (with non base 64 or base 62 characters) to make it 6 characters in length.

@hustcer
Copy link

hustcer commented Oct 5, 2016

+1 for the custom curse list feature

@cupliz
Copy link

cupliz commented Mar 7, 2017

could you tell me how to disable "curse word" feature? thanks

@niieani
Copy link
Owner

niieani commented Aug 31, 2019

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

7 participants