PHP md5() function and code snippets of md5()

md5() is one of the inbuilt function of PHP that is available from PHP 4. The md5() function can easily calculate the MD5 hash of a string. This PHP function uses the RSA Data Security, Inc. MD5 Message-Digest Algorithm.

It is really so easy to calculate the MD5 hash of a string. Below is an example of calculating the md5 of a string:

$str = "MyName";
//The below code will display the MD5 value of string MyName
echo md5($str);

In the above code we have first take the string inside a variable and then we are calculating the MD5 hash by inserting the variable. We can also directly insert the string like you can see below:

echo md5("MyName");

You can also get the MD5 hash of a file by using  md5_file() function, but in this article, we are not going to cover it.

One of the common use of md5() function was to getting the md5 value of password and storing it in the database. When the user enters the password then it will be converted in the MD5 hash and if it matches with the database, the user access will be granted.

I want to warn you that you should not use md5() PHP function for password hashing purpose. There are other methods of password hashing is available which can be recommended to secure your password.

Well, md5() was introduced in PHP for security purpose, but it is now kinda deprecated. it has too many collisions and is outdated.

Well, there are lots of developers still using md5() PHP function to hashing password. But the right way is to choose some other way that is more secure.

Leave a Reply

Your email address will not be published. Required fields are marked *