Encrypting password in php

some time due to security reason it is necessary to store encrypted password in database. In php we normally use md5() function to encrypt the password. md5() fucntion generates 32 characters hash.
It is very simple to use md5() function to encrypt the data, no matter whether it is password or something else. Following code is encrypting the password using md5()



echo $pass_encrypt;

Case Study:- We want to make a develop a module that will allow user to register by providing just two things, one is username and other is password, and then we have to encrypt the same password, insert the encrypted password in database and then whenevr user want to signin then then he can signin easily with the password he choosed using registration process.

Solution:- Following are the steps to develop such module
  1. Make a form having fields like name, email, username and password.
  2. Develop anotherpage that will deal with all encryption process, in that page you just have to recieve the form data using post or get method and assign username to some variable, let us suppose $username=$_POST['username']; and for password    $pass=$_POST['password'];
  3. Now make another variable to store the encrypted password after performing encryption process like  $encrypt_pass=md5($pass);
  4. Now simply insert the information in the database using query like this $insert_query="insert into user values('$username','$encrypt_pas')";
Now when user wants to signin just perform these two following steps
  1. Recieve form values and encrypt the password that user provide.
  2. Execute sql query that will match the username and password from the database.
Please see below the images to check full demonstration of this module