Password Encryption using md5() function In PHP



Suppose you are developing a login module with the user name and password and want to save the password into the database in the encrypted format, so that the login is more secure from the hackers. In this post I am trying to describe the password encription by using the md5() php function.
<?php
	$pass="admin";
	md5($pass);//Encryption of the password to make it more secure
?>

By the Screenshot given below you can differentiate that md5() converts the same password admin into the long string, so that it is more complicated that someone can crack your password easily.

Encryption1
Encryption2

Password generated by the md5() is not the random numbers it is fix means every time if you will encrypt the “admin” then you will get the same result “21232f297a57a5a743894a0e4a801fc3”;

Implementation of the md5() into the Login form:

<?php
	//Fetching username and password sent from form 
	$username=$_POST['username']; 
	$password=$_POST['password']; 

	// Password Encryption 
	$new_password=md5($password);
	$query="SELECT * FROM user_data WHERE userId ='$username' and user_password ='$new_password'";
	$result=mysql_query($query);
?>

but don’t forget to save the password into the Encrypted form when user is doing Signup or Registration. Create the Login Module Click Here.

You have done, now use the secure feature of the PHP, Thanks and Enjoy the coding.