I thought that maybe my login system is not as secure as I thought. So, firstly, I will tell you, in words, what I am doing.
When a user logs in, a 16 character salt is generated. I store the salt in the database in a field called "salt", I store the hashed password + salt (they are hashed together hash("sha256", $salt.$password);
) in a field called "password"
When a user tries to log in, I take the password field and the salt field from the database, as well as several other things.
To check if they entered their password correctly, I do the following:
$hashed = hash("sha256", $row['salt'].$pass); if ($row['password'] == $hashed) { //success
($ row is a selection from the database. $ row ['salt'] is the salt in the database, $ pass is the password entered, and $ row ["password"] is the hashed pass + salt in the database)
I thought, and it seems to me that my salt offers few (or none at all) security benefits. My question for all of you is this: does my method offer additional protection (or does it even protect all this?)
Also, I have a second question. I want to verify that this "check login" script cannot be faked / tricked into gaining access to a user account without their password.
session_start(); require_once 'db_connect.php'; //If the session variable "id" isn't set (ie they aren't logged in) if (!isset($_SESSION['id'])) { //Check if they wanted to be "remembered" (so they have 2 cookies if (isset($_COOKIE['rem_user']) && isset($_COOKIE['rem_pass'])) { $query = "SELECT id, password, auth, email, username FROM users WHERE username='".$_COOKIE['rem_user']."' AND active IS NULL" $res = mysql_query( $query ); if (mysql_num_rows($res) == 1) { $row = mysql_fetch_array($res); // If the "remember me" cookie containing their password // is equal to the one in the database, log them back in. if ($_COOKIE['rem_pass'] == $row['password']) { $_SESSION['id'] = $row['id']; $_SESSION['username'] = $row['username']; $_SESSION['auth'] = $row['auth']; $_SESSION['email'] = $row['email']; $logged_in = 1; } } } else $logged_in = 0; } else //Since the session variable "id" WAS set, they ARE logged in. $logged_in = 1;
I would think that the only way to log in is ...
- To trick a session variable that I don't think is possible without access to the server.
- Cheat the cookie with an encrypted password + salt, which, in my opinion, is almost impossible without access to the database.
Feedback will be appreciated. I want my system to be safe. :)
Thanks!