yomorun / hashids-java

Hashids algorithm v1.0.0 implementation in Java
http://hashids.org
MIT License
1.02k stars 156 forks source link

Add additonal prefix/suffix for salt version #29

Closed iyahimovitz closed 8 years ago

iyahimovitz commented 8 years ago

Since we are using a salt, it might be a good idea to have a version as part of the actual id. That will allow us to change the salt later if we need to. I'm not sure if this is out of scope for this library or maybe should be added as a best practice. What do you guys think?

Cheers, Itay

0x3333 commented 8 years ago

Since we are using a salt, it might be a good idea to have a version as part of the actual id. I didn't get it.

I don't believe a mutable object would be good in this case anyway.

If you want another salt, create another instance. They are relatively cheap to create and you normally shouldn't need that much instances. Just reuse them.

0x3333 commented 8 years ago

Ops...

Since we are using a salt, it might be a good idea to have a version as part of the actual id.

I didn't get it...

iyahimovitz commented 8 years ago

I meant that if you encode a version together with the id later on you could map the version to the salt/alphabet you used, that way you could change it at any given time because you always use the version to choose the alphabet and the salt. Think about it as a simple mapping: version => (salt, alphabet)

0x3333 commented 8 years ago

Oh! Know I get it. :)

This is outside of the scope of the library, which is a port of js version. If we add this we would diverge.

This could be easily done by appending the version, a number, letter, or both to the generated hash, and before decode, you get the version and use the appropriate instance.

When I get back to my computer I'll write some code to demonstrate.

iyahimovitz commented 8 years ago

cool! that's what I figured. I just thought it's worthwhile to add it as a best practice. it's always a good idea to keep some version when encoding anything.

fanweixiao commented 8 years ago

@itay1336 I will close this issue, any discussion about this we can move on :)