i wonder if someone can help me. I am trying to get this login form to work for my web application. i am using html and php, but I keep getting invalid password even if the values are correct.
i tried to fix this code and it still got the same response. below is the code in question. the way it works is, user enters password held in a database using phpmyadmin. then, if password is correct, user should be able to login, however even if it is correct it still comes back saying invalid.
$Email_Address = $Password = "";
$Email_Address_err = $Password_err = $login_err = "";
//removed code for space reasons
if (empty(trim($_POST["password"]))) {
$Password_err = "Please enter your password.";
} else {
$Password = trim($_POST["password"]);
}
if (empty($Email_Address_err) && empty($Password_err)) {
// Prepare a select statement
$sql = "SELECT user_id, Email_Address, password FROM `Login/Register` WHERE Email_Address = ?";
if ($stmt = mysqli_prepare($conn, $sql)) {
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_Email_Address);
$param_Email_Address = $Email_Address;
if (mysqli_stmt_execute($stmt)) {
// Store result
mysqli_stmt_store_result($stmt);
// Check if email exists, if yes then verify password
if (mysqli_stmt_num_rows($stmt) == 1) {
// Bind result variables
mysqli_stmt_bind_result($stmt, $user_id, $Email_Address, $hashed_password);
if (mysqli_stmt_fetch($stmt)) {
// Verify password
if (password_verify($Password, $hashed_password)) {
// Password is correct, so start a new session
session_start();
} else {
// Password is not valid
$login_err = "Invalid password.";
}
//code removed for post reasons
}
if you require any confirmation on the above code i am happy to provide, i am just quite confused why it is not working as, in my opinion, i don’t see any glaringly obvious issues. places where curly brackets or code concerning the email are missing and are alright, as i had to remove irrelevant code to upload this post. apologies for the confusion, this is my first time using this website. any help is appreciated! thank you!