I have coded md5 technique to store the password in hash but I want to implement it with salt.
here is my register form php with md5 function which is working perfectly.
<?php
require("common.php");
if (! empty ( $_POST )) {
if (empty ( $_POST ['username'] )) {
die ( "Please enter a username." );
}
if (empty ( $_POST ['password'] )) {
die ( "Please enter a password." );
}
$query = "SELECT 1 FROM User WHERE username = :username";
$query_params = array (
':username' => $_POST ['username']
);
try {
$stmt = $db->prepare ( $query );
$result = $stmt->execute ( $query_params );
} catch ( PDOException $ex ) {
die ( "Failed to run query: " . $ex->getMessage () );
}
$row = $stmt->fetch ();
if ($row) {
die ( "This user name is already registered" );
}
$password = md5($_POST['password']);
$query = "INSERT INTO User (username, password) VALUES (:username, :password)";
$query_params = array (
':username' => $_POST ['username'],
':password' => $password
);
try {
$stmt = $db->prepare ( $query );
$result = $stmt->execute ( $query_params );
} catch ( PDOException $ex ) {
die ( "Failed to run query: " . $ex->getMessage () );
}
header ( "Location: login.php" );
die ( "Redirecting to login.php" );
}
?>