You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following problem. I have a PostgreSQL table with an auto incrementing ID on rows and use hashids to encode those IDs in URLs (let's say we have 1000 rows currently). However, I need to change the salt that we are using and was wondering how I might be able to do this without adding too much complexity.
One option would be to change the path prefix of URLs so that we can know which salt to use /oldpath/:hashedid (uses old salt) /newpath/:hasedid (uses new salt), that would probably be the most simple solution, but I have to chose a new path.
Another option would be to attempt to decode the hashed id with both salts:
Decode with the old salt. If the decoded integer is between 0-1000 (largest ID at the time we switched to the new salt), use that integer.
Otherwise, decode with new salt.
The problem however is that there might be hash collisions :( (e.g. the new salt generates a hash from X that when decoded with the old salt produces an integer Y between 0-1000, which the decoding function would recognise as an old hash).
I'm running out of imagination here and was wondering if anyone else had done this before and what strategy was used.
The text was updated successfully, but these errors were encountered:
Another way of distinguishing is by ID length. If you know that all of your current IDs are 5 characters, then your new ones can be length 6 and up (use the padding param in constructor).
If that's not ideal, I'd go with the path route: /oldpath/v:hashedid
I have the following problem. I have a PostgreSQL table with an auto incrementing ID on rows and use hashids to encode those IDs in URLs (let's say we have 1000 rows currently). However, I need to change the salt that we are using and was wondering how I might be able to do this without adding too much complexity.
One option would be to change the path prefix of URLs so that we can know which salt to use
/oldpath/:hashedid
(uses old salt)/newpath/:hasedid
(uses new salt), that would probably be the most simple solution, but I have to chose a new path.Another option would be to attempt to decode the hashed id with both salts:
The problem however is that there might be hash collisions :( (e.g. the new salt generates a hash from X that when decoded with the old salt produces an integer Y between 0-1000, which the decoding function would recognise as an old hash).
I'm running out of imagination here and was wondering if anyone else had done this before and what strategy was used.
The text was updated successfully, but these errors were encountered: