Say, I have a customers with a integer PK. In my web apps I want to have a profile page for them. I do not want a url like /profile/10375/ (For example, I do not want others to know how many customers I have). I also do not want a slug base url like, /profile/acme_corp/.
What is a good way to convert unique integers to unique random short strings? (For example, earlier Reddit used to have this type of urls, but it was a conversion from decimal to base 36, skipping some ids). But that too is not useful for me as it si easy to guess number of entities in DB with this scheme.
I cant use UUID etc, as they would make the url too large.
There are some hash algorithms which produce short (8 characters, 0-9a-f) output strings, for example
adler32orcrc32. You can generate them using PHP functionhash()(seehash_algos()for a list of available algorithms), but I’m not sure your DB engine itself can handle it. If that’s the case, generating random slugs would be a better solution.And add salt when hashing, so it’s more secure.