I am having an issue getting the password being stored on in mysql to match the Login password using salt.
Here is the code from my password creation:
$hash = hash('sha256', $password);
function createSalt()
{
$text = md5(uniqid(rand(), true));
return substr($text, 0, 3);
}
$salt = createSalt();
$password = hash('sha256', $salt . $hash);
Here is the code in my login page:
$userData = $result->fetch_array(MYSQL_ASSOC);
$hash = hash('sha256', $password);
$password = hash('sha256', $userData['salt'] . $hash);
//$hash = hash('sha256', $userData['salt'] . hash('sha256', $password) );
if($password != $userData['Password']) // Incorrect password. So, redirect to login_form again.
There are no errors creating the password in mysql (the field is populated with i.e 0d02a88c1e1057a64df6b3fed4c6ad64e228313b803e9f9b36...
While the Login creates something like: 51839f9a15dac1f26825f4cd5d2ecf7ae83ea88d440415b04fb6ae41c3a0566f
Just not sure where the issue is. Thanks in advance, I am very new to PHP.
First, you have some confusing variable naming here - you use $password to represent both the plaintext password and the salt-and-hashed representation. That makes it harder to read your code.
Second, let's look at your code as a series of states to find where they might be going wrong: