Skip to content
Advertisement

PHP password_hash and password_verify weird issue not verifying [closed]

Here is my scenario:

I have a function that gives out json response when called for. Its inside a class that has the Signup.class.php included which has the Signup class. Where the GET param pass is being accessed inside the gen_hash() function as shown above. The code is below.

The code is live at https://api1.selfmade.ninja/api/gen_hash?pass=hellooo

JavaScript

This function calls Signup.class.php which has the following code:

JavaScript

The issue is as follows:

  1. The “spot_verify” array key from gen_hash() has a code that works as intended.
  2. But the “verify” array key from gen_hash() has a code that is not working as intended. It is always telling false whatsoever the case is. The hash is being generated from the Signup::hashPassword() function. It is all working as expected. The value is setting right, and is being passed to the password_hash function from within the Signup::hashPassword(). But inside gen_hash() under “verify”, it just tells false.

The code is live at https://api1.selfmade.ninja/api/gen_hash?pass=hellooo

It is giving the following answer and it makes no sense. Why is verify false?:

JavaScript

What I did already? I ensured that the same password value is being passed to password_hash and password_verify. But this makes no sense. What am I missing?

Advertisement

Answer

You’ve got an extra dollar sign here:

JavaScript

You’ve accidentally made a variable variable. Do this instead:

JavaScript

Note your code should be generating a PHP warning that points directly to the issue. So… don’t disable those.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement