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()
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
- Make a form having fields like name, email, username and password.
- 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'];
- Now make another variable to store the encrypted password after performing encryption process like $encrypt_pass=md5($pass);
- 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
- Recieve form values and encrypt the password that user provide.
- 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