Hashing passwords with PHP md5 function

Gajindu Bandara
2 min readApr 22, 2022

I recently finished a project for a first-year module in my degree program. The topic of this module was web development. I had to build and create a website for a travel firm as part of the module project. As a result, there is an admin portal for managing all site data, as well as user portals for registered users to buy trip packages.

By completing the registration form, visitors can become registered users. As a result, there’s a place where you may generate a password for the user login. I used an MYSQL database to hold all of the information about the users as well as the website’s information. So the issue was that the admin could see the user’s password after they submitted the registration form. So I used the PHP md5 method to avoid it.

MD5 stands for “message-digest algorithm 5”. As a result, this md5 hashing algorithm encrypts the user’s password into a fixed-length password. The crucial point is that we can’t decrypt an MD5 hash value to get the original input data. An MD5 password cannot be decrypted in any manner.

Let’s take a closer look at the source code. I’ll show you how to generate a 32-character hex number with the md5 function. Let’s start by making a new string variable named “$password.” We’ll next use the md5 algorithm to convert the text to a 32-character hex number.

<?php
$password = “myPassword”;
echo md5($password);
?>

The code above generates a 32-character hex number for the word “myPassword” and prints it as seen below.

deb1536f480475f7d593219aa1afd74c

The md5 function works in this manner. This function may be used to save passwords in the database as a 32-character hex number, preventing anyone with database access from seeing the real password. Only the 32-character hex number is visible to him.

--

--