Hi all, I have a logon system here but upon running the codes I found that even with the right username & right password it doesn't work.
It will just echo Sorry please try again.
Please let me know what i'm missing.
$username = filter_has_var(INPUT_POST, 'userName') ? $_POST['userName']: null;
$passWD = filter_has_var(INPUT_POST, 'pwd') ? $_POST['pwd']: null;
$username = trim ($username);
$passWD = trim ($passWD);
$loginerror = array();
if (empty($username)) {
$loginerror[] = "You have not entered all of the required fields";
}
elseif (strlen($username) < 8 OR strlen($username) > 30) {
$loginerror[] = "Username must include characters and numeric";
}
if (empty($passWD)) {
$loginerror[] = "You have not entered all of the required fields";
}
elseif (strlen($passWD) < 8) {
$loginerror[] = "You have not entered all of the required fields";
}
if (!empty($loginerror))
for ($a=0;$a<count($loginerror);$a++)
{
echo "$loginerror[$a] <br />\n";
}
else
{
include 'database_conn.php'; // make db connection
$sql = "SELECT username,passwordHash FROM users WHERE username = ? AND passwordHash =?";
$stmt = mysqli_prepare($conn, $sql); // prepare the sql statement
mysqli_stmt_bind_param($stmt, "ss", $username, $passWD);
mysqli_stmt_execute($stmt); // execute the query
mysqli_stmt_bind_result($stmt, $username, $passWDHash);
if (mysqli_stmt_fetch($stmt))
{
password_verify($passWD, $passWDHash);
echo "<p>Login successful</p>";
}
else
{
echo "<p>Sorry please try again.</p>";
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}