user2314339 user2314339 - 1 month ago 16
PHP Question

Same password values comparison returns false cakephp

I am trying to compare the input 'pass' with the 'pass' from the database. If it matches, the user will then proceed to the registration form.

Even though both passwords have the same value, I still get a false result with 'password is not correct' and a notice: Undifined index:pass.
I'm using Cakephp 2.8

This is the code I have now:

public function checkCodeRespondent() {

$password = $this->data['Respondent']['pass'];

if (isset($password) && !empty($password))
{

$respondent = $this->findByPass($password);
debug($respondent);

if ($this->data['Respondent']['pass'] != $respondent['pass']) {


print 'password is not correct';
} else {
print 'password is correct';
}


}


And this is the function to retrieve the data from database

public function findByPass($pass) {

$respondent = $this->Respondent->find('first', array('conditions' => array('pass' => $pass)));
return $respondent;
}

Answer Source

If your password is not hashed just try :

 public function checkCodeRespondent() {
 $password = $this->data['Respondent']['pass'];
 $condition = array('Respondent.pass'=>$password);
 if($this->Respondent->hasAny($condition)){
 print 'password is correct';
        } else {
            print 'password is not correct';
        }
 }

You don't need multiple function at all..