phpday 2027 - Call for Papers

md5

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

md5 — Calcola il valore md5 di una stringa

Avviso

Non è raccomandato usare questa funzione per proteggere le password, a causa della natura rapida di questo algoritmo di hashing. Vedere le FAQ sull'hashing delle password per dettagli e buone pratiche.

Descrizione

function md5(string $string, bool $binary = false): string

Calcola il valore MD5 di string utilizzando il » RSA Data Security, Inc. MD5 Message-Digest Algorithm, e restituisce tale valore.

Elenco dei parametri

string

La stringa.

binary

Se il parametro opzionale binary è impostato a true, allora viene restituito l'md5 digest in formato binario raw con una dimensione di 16.

Valori restituiti

Restituisce il valore come un numero esadecimale di 32 caratteri.

Esempi

Example #1 Un esempio di md5()

<?php
$str = 'apple';

if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
    echo "Would you like a green or red apple?";
}
?>

Vedere anche:

+add a note

User Contributed Notes 2 notes

up
8
yiminrong at yahoo dot ca
5 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
7 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