tags:

views:

16

answers:

2

I have a web application where users can login and read their messages. I use to use the ID primary key in database to access and deal with users message through the site such as (viewmessage/3) but I quickly realised I did not want to do that as it gave information to all users as to how many potential messages are stored in database. Same idea with the users, to view a users profile I use to use their ID but that gives out how many users on the site... So what I did is added a new column in each table called UrlKey, this key is a varchar(16) which is composed of 16 unique randomly generated numbers which I use to map to ID on the server side.

My question now, is 16 too much or common practice (16^10), should I use just ints or a mix of int and ascii characters, any guidelines recommendations in terms of speed, security etc...? Thanks alot

+1  A: 

16^10 is a huge number, that is over 1 trillion messages.

If you use mixed case letters and numbers, that gives you 62 characters to work with, and with 5 characters you already have 62^5 combinations, it's almost 1 billion combinations.

Bimmy
I originally used a mix but then I thought could it pose security concerns if code gets injected or so, I don't know enough so decided to play it safe and only allow numbers.
+1  A: 

Most database use a GUID or the UUID for a unique string instead of an auto incremented id. They both can be stored as a 16 bytes 128 integer but is 32 characters.

I would use a GUID or a UUID. Then you are always going to be unique.

David Basarab
I want to use this 'GUID' across the site in my url to access specific areas, the fact that it's 32 character.... could be become an an issue? You just made me realise my system is not scalable. I have a loop that generates a random key if current key already exists, so i could get stuck in this loop for quite sometime if my record gets overwhelmingly large.
@user391986 I don't see how 32 characters is an issue. And why roll your own unique identifier when it has been done for you. Every major platform would have a method to generate a GUID or UUID.
David Basarab