I'm writing an app which main purpose is to keep list of users purchases.
I would like to ensure that even I as a developer (or anyone with full access to the database) could not figure out how much money a particular person has spent or what he has bought.
I initially came up with the following scheme:
--------------+------------+----------- user_hash | item | price --------------+------------+----------- a45cd654fe810 | Strip club | 400.00 a45cd654fe810 | Ferrari | 1510800.00 54da2241211c2 | Beer | 5.00 54da2241211c2 | iPhone | 399.00
- User logs in with username and password.
- From the password calculate
user_hash
(possibly with salting etc.). - Use the hash to access users data with normal SQL-queries.
Given enough users, it should be almost impossible to tell how much money a particular user has spent by just knowing his name.
Is this a sensible thing to do, or am I completely foolish?
The user_hash will be based off of user_id which never changes. Username and password are free to change as needed. When the user logs in, you compare username/password to get the user_id. You can send the user_hash back to the client for the duration of the session, or an encrypted/indirect version of the hash (could be a session ID, where the server stores the user_hash in the session).
Now you need a way to hash the user_id into user_hash and keep it protected.
Edit: This overlaps some of the previous points. Have 3 servers:
So Employee A has user_id, username, password and algorithm. Employee B has user_hash and data. Unless employee B modifies the website to store the raw user/password, he has no way of linking to the real users.
Using SQL profiling, Employee A would get user_id, username and password hash (since user_hash is generated later in code). Employee B would get user_hash and data.