PHP Store/Insert encrypted password in MySQL database using PHP

How to convert normal password into encrypted form and save into MySQL db PhpMyAdmin.

In this tutorial we are saving the encrypted password directly into PhpMyAdmin MySQL database. We are using md5() method to encrypted  password in our page. So here is the complete step by step tutorial for PHP Store/Insert encrypted password in MySQL database using php.

android-project-download-code-button

PHP Store/Insert encrypted password in MySQL database using php.

Code for encrypted-password-page.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Encrypted Password</title>
</head>

<body>

<table>
<form action="" method="post">
<tr>
<td> Enter UserName : </td><td><input type="text" name="username"></td>
</tr>
<tr>
<td> Enter Password : </td><td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" name="submit"></td></tr>

</form>
</table>



<?php
if(isset($_POST["submit"]))
{
 
 //Including dbconfig file.
include 'dbconfig.php';
 
$username = $_POST["username"];
$password = $_POST["password"];

$EncryptPassword = md5($password);

mysql_query("INSERT INTO login (UserName,Password) VALUES ('$username','$EncryptPassword')"); 

echo " Encrypted Password Added Successfully ";

}

 ?>

</body>
</html>

Code for dbconfig.php file.

 <?php

 //This script is designed by Android-Examples.com
//Define your host here.
$hostname = "localhost";

//Define your database username here.
$username = "root";

//Define your database password here.
$password = "";

//Define your database name here.
$dbname = "test";

 $conn = mysql_connect($hostname, $username, $password);
 
 if (!$conn)
 
 {
 
 die('Could not connect: ' . mysql_error());
 
 }
 
 mysql_select_db($dbname, $conn);

 //This script is designed by Android-Examples.com

?>

Screenshot of HTML input form :

PHP Store/Insert encrypted password in MySQL database using php

Screenshot of PhpMyAdmin ( MySQL db ) :

Encrypt

Click here to download PHP Store/Insert encrypted password in MySQL database using php project with Database file included.

Leave a Reply

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