md5
(PHP 4, PHP 5)
md5 — Calculate the md5 hash of a string
Description
$str
[, bool $raw_output
= false
] )
Calculates the MD5 hash of str
using the
» RSA Data Security, Inc.
MD5 Message-Digest Algorithm, and returns that hash.
Parameters
-
str
-
The string.
-
raw_output
-
If the optional
raw_output
is set toTRUE
, then the md5 digest is instead returned in raw binary format with a length of 16.
Return Values
Returns the hash as a 32-character hexadecimal number.
Changelog
Version | Description |
---|---|
5.0.0 |
The raw_output parameter was added.
|
Examples
Example #1 A md5() example
<?php
$str = 'apple';
if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
echo "Would you like a green or red apple?";
}
?>
Notes
Note: Secure password hashing
It is not recommended to use this function to secure passwords, due to the fast nature of this hashing algorithm. See here for details.
See Also
- md5_file() - Calculates the md5 hash of a given file
- sha1_file() - Calculate the sha1 hash of a file
- crc32() - Calculates the crc32 polynomial of a string
- sha1() - Calculate the sha1 hash of a string
- hash() - Generate a hash value (message digest)
- addcslashes
- addslashes
- bin2hex
- chop
- chr
- chunk_split
- convert_cyr_string
- convert_uudecode
- convert_uuencode
- count_chars
- crc32
- crypt
- echo
- explode
- fprintf
- get_html_translation_table
- hebrev
- hebrevc
- hex2bin
- html_entity_decode
- htmlentities
- htmlspecialchars_decode
- htmlspecialchars
- implode
- join
- lcfirst
- levenshtein
- localeconv
- ltrim
- md5_file
- md5
- metaphone
- money_format
- nl_langinfo
- nl2br
- number_format
- ord
- parse_str
- printf
- quoted_printable_decode
- quoted_printable_encode
- quotemeta
- rtrim
- setlocale
- sha1_file
- sha1
- similar_text
- soundex
- sprintf
- sscanf
- str_getcsv
- str_ireplace
- str_pad
- str_repeat
- str_replace
- str_rot13
- str_shuffle
- str_split
- str_word_count
- strcasecmp
- strchr
- strcmp
- strcoll
- strcspn
- strip_tags
- stripcslashes
- stripos
- stripslashes
- stristr
- strlen
- strnatcasecmp
- strnatcmp
- strncasecmp
- strncmp
- strpbrk
- strpos
- strrchr
- strrev
- strripos
- strrpos
- strspn
- strstr
- strtok
- strtolower
- strtoupper
- strtr
- substr_compare
- substr_count
- substr_replace
- substr
- trim
- ucfirst
- ucwords
- vfprintf
- vprintf
- vsprintf
- wordwrap
Коментарии
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.
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]+$/.