PHP: md5('240610708') == md5('QNKCDZO')
1–10 of 185 posts
Re: PHP: md5('240610708') == md5('QNKCDZO')
#2Re: PHP: md5('240610708') == md5('QNKCDZO')
#3Just to make it clear, I did not come up with this example. Unfortunately I can't find out the source anymore. It also contained some technical explanations about why this works. So if anyone remembers, I'd be happy if you could comment with the link.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#4Re: PHP: md5('240610708') == md5('QNKCDZO')
#5Unless you're deliberately taking advantage of automatic type conversion and whatnot, you should probably use === by default.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#6 $ echo -n 240610708 | md5sum
0e462097431906509019562988736854 -
$ echo -n QNKCDZO | md5sum
0e830400451993494058024219903391 -
$ echo -n aabg7XSs | md5sum
0e087386482136013740957780965295 -
All of them start with 0e, which makes me think that they're being parsed as floats and getting converted to 0.0. This is why "magic" operators like == in PHP and JavaScript never should have existed in the first place. Operators like == should be, by default, extremely boring. PHP's just happens to be a bit more magical even than JavaScript's.Re: PHP: md5('240610708') == md5('QNKCDZO')
#7Re: PHP: md5('240610708') == md5('QNKCDZO')
#8PHP's == has a lot of oddball effects. They were put in so that things would behave the way a novice expects them to (3 == '3') but would confuse more experienced programmers, or those coming from other languages. Unless you're deliberately taking advantage of automatic type conversion and whatnot, you should probably use === by default.
Re: PHP: md5('240610708') == md5('QNKCDZO')
#9Re: PHP: md5('240610708') == md5('QNKCDZO')
#10OK, how did this happen?
Here all hashes are of the form "0e{digits}" which is a valid scientific notation, so when `==` internally converts them to numbers they're all parsed to `float(0)` and therefore equal, success!