2

Why is this my code returning false in my if condition at my callback code. I tried to var_dump every each of their values and

Here is the output of the var_dump

var_dump($old_password_hash); = string(32) "25d55ad283aa400af464c76d713c07ad"
var_dump($old_password_db_hash); = object(stdClass)#24 (1) { ["user_password"]=> string(32) "25d55ad283aa400af464c76d713c07ad" }

The two values doesnt satisfies in if($old_password_hash != $old_password_db_hash) {

Here is my full code

public function oldpassword_check($old_password){
    $id = $this->input->post('userid');

    $old_password_hash = md5($old_password);
    $old_password_db_hash = $this->prof_model->fetch_pwrod($id);

    //var_dump($old_password_hash);

    var_dump($old_password_db_hash);

    if($old_password_hash != $old_password_db_hash) {

        $this->form_validation->set_message('oldpassword_check', 'Old password not match');
        return FALSE;

    } else {

        return TRUE;

    } 

}
2

1 Answer 1

3

$old_password_hash is a string

$old_password_db_hash is an object

They will never be equal. string never equals object.

That's why $old_password_hash != $old_password_db_hash is always true. And therefore FALSE is returned.

Proper check is:

// take `user_password` property of an object
if ($old_password_hash != $old_password_db_hash->user_password) {
  $this->form_validation->set_message('oldpassword_check', 'Old password not match');
  return FALSE;
}
else {
  return TRUE;
}
Sign up to request clarification or add additional context in comments.

2 Comments

can you explain to me sir. how did you make the object into a string ?
I didn't. Instead I take a property of an object. And property (user_password) has type string too.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.