2

I am using:

  • PHP Version 5.2.17-MIT-BACKPORT-GnuTLS
  • SQLite 2.8.17

I have a database called users, which currently has a table called root. There will be others, once I get all the rows for root worked out, and am sure that there are now security flaws.

root stores this essential information:

  • Unique ID
  • Email
  • Salt for password
  • Hashed password
  • Time-stamp

The above rows are created with the following methods:

  • The unique ID is created with this code: uniqid(rand(1000,9999));, producing a sixteen digit unique ID, like this: 36756ceb8a84874d, made up of a four digit random number prefix (3675) and a uniqid (36756ceb8a84874d).
  • The email is a user entered string, which is stored raw in the database.
  • The salt for the password is a sixteen digit unique string like the one created for the unique ID.
  • The hashed password is created by hashing the raw password inputted by the user, with the above salt, like this: crypt($password,$salt);.
  • The time-stamp is a simple date/time number, like this: 1456388595.

My questions are these:

  1. Are the rows that I have and the techniques that I am using best practice?
  2. Are there any security flaws in them?
  3. Does anything need to be improved?
  4. Should anything be added?
  5. Can it be more efficient?

I want to get the root table working before expanding on to other tables. Maybe I should use another table called cookies, which would have rows including: id of user, id of computer, salt and hashed key?

root is the root table of the database, with all the essential information. Say it was Stack Overflow, the other tables would hold things like questions, answers, comments, reputation changes, about me, setting etc. so root is the table with all the stuff that needs to be secure, like login details, hashed password, email etc. The cookie list would be separate and for auto-logins on different devices.

5
  • SQLite version 2 ?!? And when you do not even do what the documentation suggests, this project is doomed.
    – CL.
    Commented Feb 26, 2016 at 14:43
  • @CL., please elaborate on what you mean by "when you do not even do what the documentation suggests, this project is doomed". What am I not doing?
    – Luke
    Commented Feb 26, 2016 at 20:33
  • The crypt documentation suggests not to use it. rand must not be used for crypthographic purposes (not for the ID, and especially not for the salt). And SQLite 2.8.17 is over ten years out of date. And finally, the term "security" makes sense only if you know what you want to defend against.
    – CL.
    Commented Feb 26, 2016 at 20:48
  • @CL., 1. I can't use password_hash. 2. Well what should I use instead of rand()? 3. SQLite 2.8.17 is all I can use. 4. I am using Netregistry so I really don't know how to update this stuff. People have said to use DigitalOcean, maybe at some point. 5. Any suggestions for what I might be defending against? Thanks :).
    – Luke
    Commented Feb 26, 2016 at 23:09
  • PHP 5.2 is over five years out of date. You can get unpredictable random numbers with random_int(), random_bytes(), or openssl_random_pseudo_bytes(). If some evil hacker can read your database, he can just send all users an e-mail that some evil hacker broke into your database, and that they should change their password at www.hackerz.ru/change-password.php. But it's more likely that a hacker would just replace your login page.
    – CL.
    Commented Feb 27, 2016 at 6:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.