Reputation: 29
I'm using password_verify with two arguments, the hash value that's stored in the Database, and the actual password that the user enters. Here's the code:
$pass = filter_input(INPUT_GET, 'password', FILTER_DEFAULT);
// connecting to the database and executing query, the password is stored in $dpass
if(password_verify($pass,$dpass))
echo "Hello User " . $dname;
else
echo "Login incomplete";
Now just for clarification:
Password
column in my database is a varchar(256)
password_verify()
my password with the same hash value that appeared during signup without using the database returned value (echo hash, copy & paste)BCRYPT
and DEFAULT
and they both weren't verified correctlyWhat could be the issue?
Upvotes: -2
Views: 1708
Reputation: 29
Thank you everyone for your answers, after I run my echo $pass through every line I noticed that at some point in the code it changes from its original value to a different one, I checked it again and apparently the variable $pass is used in dbconnect.php
file that is included throughout the code which has my database configurations and setup, it uses the variable $pass
to store the database password, that's what altered the value of the password, I fixed $pass to $usrPass and everything worked fine.
So for anyone in the future facing this issue and seeing this, here are the most common mistakes that lead to password_verify()
not to work:
$hash = "$2$ds$fdajja...";
using double quotes makes PHP read $2
$ds
and $fdajja...
as indivisual variables which will probably cause your code to break, USE SINGLE QUOTES INSTEAD.password_hash()
varchar(256)
, the hash is usually 60 characters long but the hashing function is frequently improved so that length may expand in the future.user2864740
for pointing that out.EDIT: Guys the password filter function did nothing at all because there was nothing to be filtered anyway, for those of you who aren't familiar with it the function basically works Input parameters, it works with both GET and POST inputs, since I'm still doing the backend part I'm using GET for testing purposes.
Upvotes: 0