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
- 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 auniqid
(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:
- Are the rows that I have and the techniques that I am using best practice?
- Are there any security flaws in them?
- Does anything need to be improved?
- Should anything be added?
- 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.
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.password_hash
. 2. Well what should I use instead ofrand()
? 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 :).random_int()
,random_bytes()
, oropenssl_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 atwww.hackerz.ru/change-password.php
. But it's more likely that a hacker would just replace your login page.