(PHP 4, PHP 5, PHP 7, PHP 8)
md5 — Возвращает MD5-хеш строки
Не рекомендуется использовать эту функцию для безопасного хранения паролей ввиду высокой скорости работы этого алгоритма. Подробнее об этом рассказывает раздел «Ответы на часто задаваемые вопросы о хешировании паролей».
Вычисляет MD5-хеш строки string, используя
» алгоритм MD5 RSA Data Security,
Inc. и возвращает этот хеш.
stringСтрока.
binary
Если необязательный аргумент binary
имеет значение true , то возвращается бинарная строка из
16 символов.
Возвращает хеш в виде 32-символьного шестнадцатеричного числа.
Пример #1 Пример использования md5()
<?php
$str = 'яблоко';
if (md5($str) === '1afa148eb41f2e7103f21410bf48346c') {
echo "Вам зелёное или красное яблоко?";
}
?>
Regarding Ray Paseur's comment, the strings hash to:
0e462097431906509019562988736854
0e830400451993494058024219903391
The odds of getting a hash exactly matching the format /^0+e[0-9]+$/ are not high but are also not negligible.
It should be added as a general warning for all hash functions to always use the triple equals === for comparison.
Actually, the warning should be in the operators section when comparing string values! There are lots of warnings about string comparisons, but nothing specific about the format /^0+e[0-9]+$/.md5('240610708') == md5('QNKCDZO')
This comparison is true because both md5() hashes start '0e' so PHP type juggling understands these strings to be scientific notation. By definition, zero raised to any power is zero.