-
Notifications
You must be signed in to change notification settings - Fork 417
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
Hashing both numbers (123) and (167) gives the same hashed id #165
Comments
If you think you've found a bug. Please provide a failing test case in the |
Something similar happened to me! Error reproduction |
@j8n as you can see, these are not the same hashes:
|
Yes ok, I cannot reproduce the error again (with test data). I had a "Integrity constraint violation: 1062 Duplicate entry" for a hash id in a record |
Ok, just to share the original as in my production env: $hash = (new Hashids\Hashids('App\Models\Subscription'.'_OUTGO', 16))->encode(501); --> "P17zevgVkZExk80a" That's how I got the error above |
This is the expected behaviour. |
What's the use of Hashids lib, if we get a "Integrity constraint violation" error in the database? The database seems to understand the case incorrectly. |
We don't recommend to store the hashids in the database. Instead encode/decode them on the fly.
|
ok thanks |
So the hashes are unique, and the behaviour is correct, the only issue is with your database being case insensitive. |
I'm saving the hashids to the DB and it is not possible to refactor the system, is there a way to make the DB queries in laravel to be case sensitive ? |
Setting up a collation in the database may help you. |
Hello
I'm generating hashed ids using the below:-
(new \Hashids\Hashids('App\Booking' . 's1lt', 10))->encode(SOME_NUMBER)
and i found that it generated two identical hashed ids although the numbers are different (123 and 167)
so both
(new \Hashids\Hashids('App\Booking' . 's1lt', 10))->encode(123)
and
(new \Hashids\Hashids('App\Booking' . 's1lt', 10))->encode(167)
gives the hash
Dkq1ZKnyWa
Why is this happening ?
Thanks in advance.
The text was updated successfully, but these errors were encountered: