Comparison Operator won't work?


echo $this->password;

			echo $user->password;

            if ($this->password == $user->password ) {

                

				$this->errorCode = self::ERROR_NONE;

				echo $user->role_id;

            } else {

				

                // = $user->id;

				$this->errorCode = self::ERROR_PASSWORD_INVALID;

               

            }

This code will go to the false statement even if it’s true… WHY?

The two variables must be different. What do the two echo statements produce?

It echoes out the two variables… So that I would know if it’s the same or not… Even if it prints the same, it still chooses false…

What gives var_dump() of the two variables?

Are you sure there isn’t a trailing or leading space in the password? Your best bet is do what sjakie said and var_dump() the variables.

I just var_dump the two variables:

user->password = string(16) "pop"

this->password = string(4) "pop"

but then I tried to space it out until…

user->password = string(16) "pop"

this->password = string(16) "pop"

But it won’t still login, and How do I solve this “space problem”. Thanks

It’s probably not spaces in user->password. How is that value getting populated? It looks like you have some weird control characters on your passwords because this->password = string(4) “pop” says a length of 4 when clearly it should be 3. You can try trimming both passwords, but it looks like you have an issue populating your passwords.

Why did you try to space it out? You better can try to remove all spaces.

Can you try this before comparing the passwords




$user->password = str_replace(" ","",$user->password);

$this->password = str_replace(" ","",$this->password);



Assuming they are spaces and not some hidden control character or line feed. I would try to understand why the lengths are wrong first, because there might be an issue some place else.

Sorry, it is "popo" not pop… typo there…

Does not change a thing… :( It still the same.

I just want to compare passwords typed and password store in database


$username=strtolower($this->username);

		$user = User::model()->findByAttributes(array('username' => $this->username));

        if ($user === null) {

            $this->errorCode = self::ERROR_USERNAME_INVALID;

        } else {

			var_dump($user->password);

			var_dump($this->password);

       ---* if ($user->password != $this->password) { *--------

                $this->errorCode = self::ERROR_PASSWORD_INVALID;

            } else {

                $this->_id = $user->id;

                $this->errorCode = self::ERROR_NONE;

            }

        }

        return !$this->errorCode;