<?php
require "Common.php";
$player_username = $_POST ["usernamePost"];
$player_password = $_POST ["passwordPost"];
$hashed_password = password_hash($player_password, PASSWORD_DEFAULT);
$conn = new mysqli ($server_host, $server_username, $server_password, $server_dbName);
$result = mysqli_query ($conn, "SELECT * FROM users WHERE Username ='$player_username' and Password = ''");
$count = mysqli_num_rows($result);
if ($count == 1) {
while ($row = mysqli_fetch_assoc ($result)) {
if (password_verify($player_password, $hashed_password)) {
echo "Signing in...<br>";
echo "ID:".$row ['ID'] . "|Username:".$row ['Username'] . "|Score:".$row ['Score'] . "|Status:".$row ['Status'];
}
}
}
else {
echo "Incorrect username or password.";
}
?>
Second piece of code:
<?php
require "Common.php";
$player_username = $_POST ["usernamePost"];
$player_password = $_POST ["passwordPost"];
$hashed_password = password_hash($player_password, PASSWORD_DEFAULT);
$conn = new mysqli ($server_host, $server_username, $server_password, $server_dbName);
$queryCode = "SELECT * FROM users WHERE Username = '$player_username'";
$query = mysqli_query ($conn, $queryCode);
if (mysqli_num_rows($query) > 0) {
echo "Username already exists.";
} else {
$sql = "INSERT INTO users (Username, Password)
VALUES ('".$player_username."','".$hashed_password."')";
$result = mysqli_query ($conn,$sql);
echo "User created.";
}
?>
I can create an account with a hashed password, however, I cannot login with it. I've looked at every post regarding my issue on this website. It's either that I was looking at the wrong thread or I simply did not understand what they were doing.