Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why md5('240610708') is equal to md5('QNKCDZO')? [duplicate]

Tags:

php

md5

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

Output:

bool(true) 

Example: http://3v4l.org/2vrMi

like image 985
Farid Movsumov Avatar asked Mar 03 '14 06:03

Farid Movsumov


People also ask

How to compare two md5 strings in PHP?

php $filename = 'hash. txt'; $handle = fopen($filename, 'r'); echo $file_password = fread($handle, filesize($filename)); $name=md5('bimbo'); if($name==$file_password){ echo "string"; } ?>

Why we use md5 in PHP?

The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA." To calculate the MD5 hash of a file, use the md5_file() function.

How does md5 password compare?

Convert user entered password to md5 and then check. $user_entered_pass_has = md5($user_entered_pass) Then check for equality. Show activity on this post.


1 Answers

md5('240610708') 's result is 0e462097431906509019562988736854.

md5('QNKCDZO') 's result is 0e830400451993494058024219903391.

They are both float number format strings (numerical strings), and if you use == in php, when compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.

Both of the strings are converted to 0 when compared with ==, if you want to compare them as string, remember to use ===(strict comparison) instead.

See: PHP expresses two different strings to be the same

like image 53
xdazz Avatar answered Oct 14 '22 13:10

xdazz