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?
Keith
(Kburton)
August 30, 2012, 4:20pm
2
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…
sjakie
(Arjanwestdorp)
August 30, 2012, 6:09pm
4
What gives var_dump() of the two variables?
cnick79
(Cnick79)
August 30, 2012, 6:34pm
5
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
cnick79
(Cnick79)
August 30, 2012, 6:58pm
7
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.
sjakie
(Arjanwestdorp)
August 31, 2012, 6:56am
8
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
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);
cnick79
(Cnick79)
August 31, 2012, 1:22pm
9
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.
cnick79:
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.
Sorry, it is "popo" not pop… typo there…
sjakie:
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);
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;