Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - password_verify issue
    primarykey
    data
    text
    <p>I have been scratching my head on this for over 2 hours. I have researched articles on stackoverflow including:</p> <ul> <li><p><a href="https://stackoverflow.com/questions/16246082/issue-with-bcrypt-not-verifying-correctly">Issue with Bcrypt not verifying correctly</a></p></li> <li><p><a href="https://stackoverflow.com/questions/19855715/php-password-hash-and-password-verify-issues-no-match">php password_hash and password_verify issues no match</a></p></li> <li><p><a href="https://stackoverflow.com/questions/15090481/password-verify-call-returning-false-for-correct-password">`password_verify` call returning false for correct password</a></p></li> </ul> <p>And I havent been able to correct my issue. I would appreciate some guidance on how much of an idiot I am being:</p> <p><strong>Function to insert data into MySQL database:</strong></p> <pre><code>function insertUser($userObj) { $query = $this-&gt;databaseConnection-&gt;getStntPrepare()-&gt;prepare( "INSERT INTO user(username, userpassword) VALUES (?,?);"); $username = $userObj-&gt;getUsername(); $password = password_hash('testing1234', PASSWORD_BCRYPT); $query-&gt;bind_param('ss', $username, $password); } </code></pre> <p><strong>Verification of user login by retrieving data from MySQL:</strong></p> <pre><code>function findUser($userObj) { $query = $this-&gt;databaseConnection-&gt;getStntPrepare()-&gt;prepare( "SELECT userid, userpassword FROM user WHERE username=?"); $pass = 'testing1234' $query-&gt;bind_param('s', $userObj-&gt;getUsername()); $query-&gt;execute(); $query-&gt;bind_result($userid, $hash); while ($query-&gt;fetch()) { if (password_verify($pass, $hash)) { echo 'Password is valid!'; } else { echo 'Invalid password.'; } } } </code></pre> <p>When run I get 'Invalid password.'</p> <p><strong>When I do the below without inserting into database then retrieving:</strong></p> <pre><code>$hash = password_hash('testing1234', PASSWORD_BCRYPT); if (password_verify('testing1234', $hash)) { echo 'Password is valid!'; } else { echo 'Invalid password.'; } </code></pre> <p>I get 'Password is valid!'</p> <p>I believe my problem is something to do with single and double quotes and the interpretation of dollar sign ($) in the password field, as a variable instead of literal (as one of the articles suggests) when storing/retrieving from MySQL database - however I haven't had any luck in resolving. Below is the hash value of 'testing1234':</p> <p>$2y$10$1/oQEuYX67n.U3usxH.7tenNq7hT2dKyBSIZsy5xR3W</p>
    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.
 

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