PHP 8.5.0 Alpha 1 available for testing

md5

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

md5Calcula el md5 de un string

Advertencia

No se recomienda utilizar esta función para contraseñas seguras debido a la naturaleza rápida de este algoritmo de «hashing». Véase las Preguntas más frecuentes de «hash» de contraseñas para más detalles y el empleo de mejores prácticas.

Descripción

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

Calcula el MD5 del string string utilizando el algoritmo » RSA Data Security, Inc. MD5 Message-Digest Algorithm, y devuelve el resultado.

Parámetros

string

El string.

binary

Si el argumento opcional binary está definido a true, entonces el md5 se devuelve en formato binario crudo con una longitud de 16.

Valores devueltos

Devuelve el md5 del string, en forma de un número hexadecimal de 32 caracteres.

Ejemplos

Ejemplo #1 Ejemplo con md5()

<?php
$str
= 'apple';

if (
md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
echo
"¿Desea una golden o una spartan?";
}
?>

Ver también

  • hash() - Genera un valor de hachado (huella digital)
  • password_hash() - Crea una clave de hash para una contraseña

add a note

User Contributed Notes 2 notes

up
16
yiminrong at yahoo dot ca
4 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
1
Ray.Paseur sometimes uses Gmail
6 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