-1

I hashed a password through

$hashedpassword = password_hash($Password, PASSWORD_DEFAULT);

This stores the password as a hashed value into a database. But when I try to login in through

$Password=$_POST['Password'];

$hashedpassword = password_hash($Password, PASSWORD_DEFAULT);
if(password_verify($Password, $hashedpassword))

It will always tell me that the password is correct, regardless on whether it is or not. Is there a way around this, so I can hash the password but login with the entered (non-hashed) password.

John Conde
  • 217,595
  • 99
  • 455
  • 496
JakeL
  • 1
  • 1

1 Answers1

2

At some point in the past, when the account was created or when the password was last changed, you should have stored the hashed password.

You need to get the stored password hash from the database and use that with password_verify.

Currently, you are hashing the newly submitted password and verifying the submitted password against that, so of course, it always matches.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335