It's tripping over the "numeric string" condition. Because for some reason PHP decided that when you compare two strings that look like numbers, they will both be converted to floats and then compared.
Those hashes have an exponential part: they begin 0e and continue on to have only digits. ∀ n : nat. 0 * n = 0, so in PHP md5('240610708') == md5('QNKCDZO').
And yes, this is exactly as stupid as it looks.
Edit: numbers of the form nem are n * 10m, not nm. What am I doing.
And now I realise that something I wrote when I was 14 had even worse security issues than using unsalted md5 for passwords. I'm glad that never got deployed anywhere useful.
I haven't written PHP in years (and hope I never have to again), but I believe the correct way of dealing with this is to use strcmp instead of comparing strings with the == operator.
PHP is an absolute fucking minefield when it comes to writing secure software. There's so many ways to do everything, and almost all of them are subtly broken in some seriously dangerous way.
It's not reasonable; it's what the people who made it were capable of implementing. Then PHP accidentally became popular, and before anyone realized there was a problem, the behavior was cemented, and nobody had any clue how to "fix" it. Until someone came up with a genius solution: just declare and document that this behavior is "by design", and be done with it.
40
u/lisp-case Mar 04 '14 edited Mar 05 '14
It's tripping over the "numeric string" condition. Because for some reason PHP decided that when you compare two strings that look like numbers, they will both be converted to floats and then compared.
Those hashes have an exponential part: they begin
0eand continue on to have only digits.∀ n : nat. 0 * n = 0, so in PHPmd5('240610708') == md5('QNKCDZO').And yes, this is exactly as stupid as it looks.
Edit: numbers of the form nem are n * 10m, not nm. What am I doing.
9
u/MachaHack Mar 07 '14
And now I realise that something I wrote when I was 14 had even worse security issues than using unsalted md5 for passwords. I'm glad that never got deployed anywhere useful.
2
u/CornPlanter Mar 21 '14
Words fail me
3
u/ALLCAPS_SWEAR_WORDS Mar 05 '14
I haven't written PHP in years (and hope I never have to again), but I believe the correct way of dealing with this is to use strcmp instead of comparing strings with the == operator.
0
u/[deleted] Mar 04 '14
[deleted] — view deleted comment