1

I've been trying to compare password values using a custom form.

Actually I want to show a relogin form after a particular amount of time. So I have created a custom form with two fields – email and password. And now I want to compare the password input from my custom form with the user's password stored in the database. If the passwords are same, then the user will be allowed to access the site agin.

I can't compare the hashed password with the custom form password. I know we can't compare the password values, because the password in the database is hashed.

Is any other way to compare them?

1

The only advisable approach would be to use user_check_password:

$account = user_load(123);
$valid = user_check_password($password_from_form_submission, $account);
if ($valid) {...}

If you desperately need to do it manually, just copy the parts of that function that make sense for your requirements.

  • I done same as like the above. It returns 1. Is this right? – User1254 Oct 29 '18 at 11:22
  • @User1254 – 1 is TRUE. – leymannx Oct 29 '18 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.