Dutch PHP Conference 2025 - Call For Papers

md5

(PHP 4, PHP 5, PHP 7, PHP 8)

md5Обчислює MD5-хеш рядка

Увага

Не рекомендовано використовувати цю функцію для захисту паролів через її швидкий алгоритм гешування. Докладніше: ЧаПи щодо гешування паролів.

Опис

md5(string $str, bool $raw_output = false): string

Обчислює MD5-хеш рядка str використовуючи » RSA Data Security, Inc. MD5 Message-Digest Algorithm, та повертає цей хеш.

Параметри

str

Рядок.

raw_output

Якщо необов'язковий параметр raw_output встановлений у true, то повертається бінарний рядок з 16 символів.

Значення, що повертаються

Повертає хеш у вигляді 32-символьного шістнадцяткового числа.

Приклади

Приклад #1 Використання md5()

<?php
$str
= 'Яблуко';

if (
md5($str) === '58bb8ca76e4a13037e7cd0232f387643') {
echo
"Вам яке яблуко? Червоне чи зелене?";
}
?>

Прогляньте також

  • md5_file() - Обчислює MD5-хеш файлу
  • sha1_file() - Обчислює SHA1-хеш файла
  • crc32() - Обчислює CRC32-поліном для рядка
  • sha1() - Обчислює SHA1-хеш рядка
  • hash() - Generate a hash value (message digest)
  • crypt() - One-way string hashing
  • password_hash() - Creates a password hash

add a note

User Contributed Notes 2 notes

up
15
yiminrong at yahoo dot ca
3 years ago
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]+$/.
up
5
Ray.Paseur sometimes uses Gmail
5 years ago
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.
To Top