If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > should primary key be exposed?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-07, 00:49
ytubber ytubber is offline
Registered User
 
Join Date: Jul 2007
Posts: 3
should primary key be exposed?

hi all

I have a table named "members" and it contains the following fields: member_id(key), username, pwdhash, email. The primary key is member_id and this id is used as foreign key to other tables.

In my web application, should the member_id be ever be exposed to the end user without encryption? For example www.jone.com?userid=1 will retreive records of member_id=1 in "members" table.

thanks

Last edited by ytubber; 12-02-07 at 01:01.
Reply With Quote
  #2 (permalink)  
Old 12-02-07, 01:22
blindman blindman is offline
World Class Flame Warrior
 
Join Date: Jun 2003
Location: Ohio
Posts: 11,726
MemberID is a surrogate key, and as such you should avoid exposing it to the user because, of itself, it contains no information.
I'd assume that USERNAME is a unique value, and this is what you should display in your application.
__________________
If it's not practically useful, then it's practically useless.

blindman
www.chess.com: "sqlblindman"
Reply With Quote
  #3 (permalink)  
Old 12-02-07, 02:07
ytubber ytubber is offline
Registered User
 
Join Date: Jul 2007
Posts: 3
ok. noted. thanks.
Reply With Quote
  #4 (permalink)  
Old 12-03-07, 12:58
amthomas amthomas is offline
Registered User
 
Join Date: May 2005
Location: San Antonio, Texas
Posts: 134
I agree with blindman, but would like to point out that there is nothing inherently insecure about showing "www.jone.com?userid=1" since it is just another piece of data (although meaningless to a user). The problem there is if you allowed them to change the userid to something else to try to view other users. This really isn't a database security issue so much as an application security issue. You application will have to check the permissions of any action you do to make sure the user is authorized to view the information.

the '1' should really just be a meaningless number to the user. Showing it shouldn't matter other than they won't know what it is. Using www.jone.com?username=amthomas instead of www.joine.com?userid=1 won't make yoru application any more secure.. you still have to do the same security checks.

If you are talking about showing it on a view form then there is no point.
__________________
Vi veri veniversum vivus vici
By the power of truth, I, a living man, have conquered the universe
Reply With Quote
  #5 (permalink)  
Old 12-03-07, 13:26
Thrasymachus Thrasymachus is offline
SQL Server Street Fighter
 
Join Date: Nov 2004
Location: Down The Rabbit Hole
Posts: 7,979
Quote:
Originally Posted by amthomas
I agree with blindman, but would like to point out that there is nothing inherently insecure about showing "www.jone.com?userid=1"
except for the fact that this leaves you open to URL hacking. data passed along the query string will not pass the internal audits at the company i work for.
__________________
software development is where smart people go to waste their lives
Reply With Quote
  #6 (permalink)  
Old 12-03-07, 14:26
amthomas amthomas is offline
Registered User
 
Join Date: May 2005
Location: San Antonio, Texas
Posts: 134
I mentioned that.

My point is hiding stuff does not automatically secure a program. The security should be there anyway whether shown or not. Your company can have a 'hide' policy but that doesn't automatically make it secure.

How do you load up the userid as in the above case? store everything in the session? There are some that would arguing that using the session like that is bad programming.
__________________
Vi veri veniversum vivus vici
By the power of truth, I, a living man, have conquered the universe
Reply With Quote
  #7 (permalink)  
Old 12-03-07, 18:38
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
If USERNAME is unique, then why have you got a USERID?
__________________
George
Twitter | Blog
Reply With Quote
  #8 (permalink)  
Old 12-03-07, 23:08
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by georgev
If USERNAME is unique, then why have you got a USERID?
because the database developer drank the surrogate key koolaid
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 12-04-07, 00:26
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by georgev
If USERNAME is unique, then why have you got a USERID?
In my case at least, because the data modeler is a skeptical, cynical type of person.

The following are my opinions, but they have served me well for decades and I'm not likely to give them up without a considerable fight. Attribute values that the user can see, they are tempted to change. Surrogate keys should exist for the convenience of the application/database only, and should NEVER be visible to the end user.

In this example, the user knows and uses the USERNAME, which is as it ought to be. In my world, the user will never see and should never even know that the USERID exists!

-PatP
Reply With Quote
  #10 (permalink)  
Old 12-04-07, 00:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
okay, pat, but you didn't really answer george's question

what does cynicism and skepticism have to do with declaring an extra surrogate key when a perfectly good natural key exists?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 12-04-07, 05:57
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
DBForums uses a surrogate userID...
How come that is exposed?
__________________
George
Twitter | Blog
Reply With Quote
  #12 (permalink)  
Old 12-04-07, 06:33
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Quote:
Originally Posted by amthomas
How do you load up the userid as in the above case? store everything in the session? There are some that would arguing that using the session like that is bad programming.
I have no idea of best practice for this stuff - I only dev. internal ASP.NET stuff rather than secure, client facing sites but I do prefer to use sessions for this. Any references for why this might be considered bad practice?
Reply With Quote
  #13 (permalink)  
Old 12-04-07, 07:40
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by r937
okay, pat, but you didn't really answer george's question

what does cynicism and skepticism have to do with declaring an extra surrogate key when a perfectly good natural key exists?
As I observed:
Quote:
Originally Posted by Pat Phelan
Attribute values that the user can see, they are tempted to change. Surrogate keys should exist for the convenience of the application/database only, and should NEVER be visible to the end user.
-PatP
Reply With Quote
  #14 (permalink)  
Old 12-04-07, 07:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
okay, pat, i guess you don't understand what i'm asking, so i'll just let it slide, as i don't want you to get frustrated with me yet once again for persisting in asking a question that you aren't answering
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #15 (permalink)  
Old 12-04-07, 08:39
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
I'm gonna hazard a guess based on Pat's answers in previous threads:
1) Users change stuff what they can
2) Based on 1), don't use natural keys

3) Based on one and two, use a surrogate
4) Don't expose your surrogate

1 & 2 are I think what Pat considers an answer to your question. 3 & 4 are a bonus.

Out of curiosity Pat - your problem is to do with referential integrity of natural keys? You presumably enforce uniqueness of your natural alternate key right?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On