Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the best place to put database ids on the client-side?

I'm serving up a page using ASP.Net. I have Add/Edit/Delete functionality of controls I've added dynamically using jQuery on a page, some of which have related records in a database. Where is the best place to put the id (primary key) for these, an attribute, data-*, jQuery.data()? Should I be concerned if the Id is visible client-side?

like image 561
Homer Avatar asked Dec 16 '22 13:12

Homer


2 Answers

It's good practice to encrypt the ID of the record on the client side to ensure the security of your database. Usually a hidden field will do the trick.

This way, the user only sees the encrypted id upon viewing the source. The script being called then uses the key used to encrypt to retrieve the record identifier server side and manipulate data as needed.

like image 196
zgr024 Avatar answered Dec 24 '22 14:12

zgr024


Firstly do not use the direct database ID. You will be tied to directly to one version of one table's Primary Key. Instead create a second column, using UUID to be the place holder of primary key

for example

tbl_person
 person_id INT PRIMARY KEY
 person_uuid VARCHAR(64)
 name VARCHAR(128)

But to answer the actual question, I suggest you use an attribute of the appropriate element, proabbly id

<tr><td id="1234-5678">Paul </td></tr>

(edit to get code formatting right)

like image 34
lifeisstillgood Avatar answered Dec 24 '22 14:12

lifeisstillgood