How to Create MD5 Hashes in PHP ?
Last Updated :
05 Jan, 2024
MD5 is a widely used hash function that produces a fixed-size 128-bit hash value from arbitrary input data. In PHP, creating MD5 hashes is a common task, often used for password hashing, data integrity verification, or generating unique identifiers. In this article, we’ll explore different approaches to create MD5 hashes in PHP, these are:
Approach 1: Using md5 Function
The basic method for creating MD5 hashes in PHP is by using the built-in md5 function.
PHP
<?php
$str = "Hello, MD5!" ;
$hashStr = md5( $str );
echo "MD5 Hash: $hashStr" ;
?>
|
Output
MD5 Hash: 383e139e64e5f46de9d03ba3695da2d8
Approach 2: Using hash Function with “md5” Algorithm
PHP provides the hash function that supports various hashing algorithms, including MD5.
PHP
<?php
$str = "Hello, MD5!" ;
$hashStr = hash( "md5" , $str );
echo "MD5 Hash: $hashStr" ;
?>
|
Output
MD5 Hash: 383e139e64e5f46de9d03ba3695da2d8
Share your thoughts in the comments
Please Login to comment...