Primary key with randomly varying increments (so it cannot be guessed easily)
6
votes
4
answers
6485
views
I would like the primary keys to be auto-incremented and generated but in varying increments. For ex, if I have increment range as 100... then the auto generated keys would be something like below:
- 20 (random number between 1 and 100)
- 30 (add random number 10 that's between 1 and 100)
- 113 (add random number 83 that's between 1 and 100)
- 118 (add random number 5 that's between 1 and 100)
- 217 (add random number 99 that's between 1 and 100)
- 220 (add random number 3 that's between 1 and 100)
The data domains are often exposed via HTTP REST endpoints, and I would like the end users to not able to guess the primary keys by simply incrementing numbers.
I'm trying to avoid UUID/GUIDs if possible. My REST URLs are longer, often with parent-child identifiers. (Yes, it's avoidable but I prefer it for simpler testing/troubleshooting). So I prefer numbers as identifiers.
Is there any simpler solution that I'm not aware of? I'm using PostgreSQL but any generic solution is also fine.
Asked by Karthik Karuppannan
(161 rep)
Jul 16, 2014, 07:31 PM
Last activity: Jan 16, 2021, 06:47 AM
Last activity: Jan 16, 2021, 06:47 AM