I have the following code which is correct and working fine,it creates a salt value when entered into the MySQL database..
The issue I am facing is when trying to login with the while using the salted value, something is missing from my code (2nd bit of code on this post is the login which) the one causing issues.
$result = $conn->prepare("INSERT INTO members (name, username, email, salt, password, age, gender, gender_of_dogs) VALUES (:name, :username, :email, :salt, :password, :age, :gender, :gender_of_dogs)");
$result->bindParam(':name', $value1);
$result->bindParam(':username', $value2);
$result->bindParam(':email', $value3);
$result->bindParam(':salt', $salt);
$result->bindParam(':password', $hashedPassword);
$result->bindParam(':age', $value5);
$result->bindParam(':gender', $value6);
$result->bindParam(':gender_of_dogs', $value7);
$value1 = $_POST['name'];
$value2 = $_POST['username'];
$value3 = $_POST['email'];
$salt = uniqid('', true);
$value4 = $_POST['password'];
$value5 = $_POST['age'];
$value6 = $_POST['gender'];
$value7 = implode(',', $_POST['gender_of_dogs']);
$hashedPassword = md5($salt.$value4);
$result->execute();
echo "<h2>Thank you for registering, <br> You will now be redirected to the homepage...</h2>";
header( "refresh:5; url=../index.php" );
Below is the code when trying to login, it will not let me login as it is not getting the unique salt value in the MySQL database.
( At least I think that is the issue. )
include('../db_connect.inc');
$username = $_POST['username'];
$password = $_POST['password'];
$salt = $_POST['salt'];
$hashedPassword = md5($salt.$password);
$query = $conn->prepare("Select * from dog_parks.members where username = :username_login and password = :password_login ");
$query->bindParam(':username_login', $username);
$query->bindParam(':password_login', $hashedPassword);
$query->execute();
$count = $query->rowCount();
$row = $query->fetch();
if ($count > 0) {
session_start();
$_SESSION['id'] = $row['username'];
header('location:home.php');
}
