2

I wonder why this code return true instead of false

var_dump(md5('240610708') == md5('QNKCDZO'));

Thanks in advance, any explanation will be appreciated.

Dark Cyber
  • 2,181
  • 7
  • 44
  • 68

2 Answers2

1

Try this instead:

var_dump(md5('240610708') === md5('QNKCDZO'));
Sloan Thrasher
  • 4,953
  • 3
  • 22
  • 40
1

Looks, like these md5 hashes, which starts from '0e', are parsed by PHP as a decimal numbers with exponent (see var_dump(100 == "1e2"); // 100 == 100 -> true from Comparison Operators).

That is why they are interpreted as equals. To avoid this, must use strict comparison.

Update:

And strcmp gives the correct result, too. If I understand correctly, because there is no conversions in case of strcmp.

ghostprgmr
  • 488
  • 2
  • 11