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?

0

1 Answer 1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.