tirenweb
tirenweb

Reputation: 31749

PHP comparion doesnt work..why?

i have this code:

    $password_introducido = sfContext::getInstance()->getUser()->getGuardUser()->setPassword($value['password_actual']);

    $password_almacenado = sfContext::getInstance()->getUser()->getGuardUser()->getPassword();

    var_dump("kfjsdlkjf");
    var_dump($password_almacenado);
    var_dump($password_almacenado);

    if($password_introducido == $password_almacenado){

        die("entrosopi");


    }

that prints this:

string 'kfjsdlkjf' (length=9)

string 'c9c40d11b29ac0f5bdef3be51ce61187582c3ae1' (length=40)

string 'c9c40d11b29ac0f5bdef3be51ce61187582c3ae1' (length=40)

IMHO, it should print "entrosopi", but it doesnt. Why?

If i instead write

if(!$password_introducido == $password_almacenado)

it prints "entrosopi".

Javi

Upvotes: 0

Views: 137

Answers (3)

Tyler Carter
Tyler Carter

Reputation: 61577

You realize you are outputting the same string right?

Try this:

var_dump("kfjsdlkjf");
var_dump($password_introducido);
var_dump($password_almacenado);

Tell us what it outputs.

They are most likely NOT equal to each other.

Upvotes: 4

dreeves
dreeves

Reputation: 26962

Use === for exact, literal comparison.

For details, see this related question: if(0 == '%') echo "WTF, Php, why can't you compare things sanely?"

Upvotes: 0

webbiedave
webbiedave

Reputation: 48887

One of the functions (most likely setPassword) is encrypting/hashing the value for security.

Upvotes: 0

Related Questions