Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are not using prepared statements (you should), and so your MySQL query's varchar fields need escaping with quotes, for example:</p> <pre><code>$dbsalt = mysqli_query($con,"SELECT salt FROM students WHERE username = '$user'"); $dbhash = mysqli_query($con,"SELECT hash FROM students WHERE username = '$user'"); </code></pre> <p>Notice the quotes around <code>$user</code>.</p> <p>Additionally, you are trying to access the data from the query directly from the result given by mysqli_query (which is actually an an object containing the data), instead, you should use like this:</p> <pre><code>$dbresult = mysqli_query($con,"SELECT salt, hash FROM students WHERE username = '$user'"); $row = $dbresult-&gt;fetch_row(); if(testPassword($pwd, $row['salt'], $row['hash'])) .... </code></pre> <p>Edit: after looking more closely, there are also a few other 'optimisations' you might like to consider; there is no need to assign the <code>$_SESSION</code> and <code>$_GET</code> arrays to separate variables before using them (and this may also be a reason why your data isn't getting 'stored', if you were referring to the session data?), and you only need 1 database query for your script:</p> <pre><code>&lt;?php function testPassword($fpwd, $fdbsalt, $fdbhash) { return hash_hmac("sha256", $fpwd, $fdbsalt) == $fdbhash; } $user = $_GET['username']; $pwd = $_GET['password']; include('Connect.php'); $dbresult = mysqli_query($con,"SELECT salt, hash FROM students WHERE username = '$user'"); $found = mysqli_num_rows($dbresult); if($found &lt; 1) { header('Location: Login.php?msg=Username%20incorrect!'); } else { $row = $dbresult-&gt;fetch_row(); if(testPassword($pwd, $row['salt'], $row['hash'])) { session_start(); $_SESSION['user'] = $user; if($user === "00000000") { header('Location: Students.php'); } else { header('Location: Display.php'); } } else { header('Location: Login.php?msg=Password%20incorrect!'); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload