tags:

views:

54

answers:

3

Hi,

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

+4  A: 

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.

Chacha102
No it's not. The first one will convert `$password_introducido` to a boolean, `NOT` it and then compare *that* to `$password_almacenado`.
Samir Talwar
@Samir Thank you for that correction.
Chacha102
A: 

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

webbiedave
A: 

Use === for exact, literal comparison.

For details, see this related question: http://stackoverflow.com/questions/2322789/if0-echo-wtf-php

dreeves