Last updated on September 8, 2023
In PHP, there are several functions and methods that can be used to securely hash and encrypt passwords. Below is the list,
md5() Function:
In PHP, md5 function is commonly used password encryption method which stands for MD5 Message-Digest Algorithm. It is not recommended for secure passwords. It is a one-way hashing algorithm and supported by PHP versions PHP 4, 5, 7, and 8.
Parameters:
The md5() function takes two parameters the first is required and the second is optional. The default is FALSE.
Syntax:
md5(string,raw);
Return values:
Look at the below example in which we passed string into md5() function to make the 32-character hexadecimal hash.
$string = "YouPasswordHere";
echo md5($string);
// output : f91adb38d9f43c865c1254a975eaa210.
In the above example, we print the hash value generated by the md5() function.
Look at another example in which we set optional binary parameter to true and passed the string.
$string = "YouPasswordHere";
echo md5($string, true);
// output : ��8��<�\T�u�
In this example, we passed the string to md5() function and set second argument to true which returns 16-byte string.
Conclusion :
This article explains PHP built-in functions that is used to encrypt the passwords along with examples.