alexandre Posted November 1, 2022 Share Posted November 1, 2022 since i had to redo my database everything is messed up.. now i cant get to login to my website anymore but my file didnt changed from the time it was working fine , except for the database credentials. if anyone could take a look at this very small code i would appreciate, no matter what i do it keeps returning that i entered a incorrect password or username, it wont succeed to make the match with the data pulled from the database. heres the authenticate.php: <?php session_start(); include 'connect_db2.php'; if (!isset($_POST['username'], $_POST['password'])) { // Could not get the data that should have been sent. exit('Please fill both the username and password fields!'); } // Prepare our SQL, preparing the SQL statement will prevent SQL injection. if ($stmt = $con->prepare('SELECT id, username, password FROM accounts WHERE username = ?')) { // Bind parameters (s = string, i = int, b = blob, etc), in our case the username is a string so we use "s" $stmt->bind_param('s', $_POST['username']); $stmt->execute(); // Store the result so we can check if the account exists in the database. $stmt->store_result(); if ($stmt->num_rows > 0) { $stmt->bind_result($id, $username, $password); $stmt->fetch(); // Account exists, now we verify the password. // Note: remember to use password_hash in your registration file to store the hashed passwords. if (password_verify($_POST['password'], $password)) { // Verification success! User has logged-in! // Create sessions, so we know the user is logged in, they basically act like cookies but remember the data on the server. session_regenerate_id(); $_SESSION['loggedin'] = TRUE; $_SESSION['name'] = $username; $_SESSION['id'] = $id; header('location: home.php'); exit; } else { // Incorrect password echo 'Incorrect username and/or password!'; } } else { // Incorrect username echo 'Incorrect username and/or password!'; } $stmt->close(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/315480-cant-get-the-authentication-to-work-anymore/ Share on other sites More sharing options...
alexandre Posted November 1, 2022 Author Share Posted November 1, 2022 i just verified and this is the password not matching. it is a hashed password stored in database after registration . Quote Link to comment https://forums.phpfreaks.com/topic/315480-cant-get-the-authentication-to-work-anymore/#findComment-1602137 Share on other sites More sharing options...
Solution alexandre Posted November 1, 2022 Author Solution Share Posted November 1, 2022 it is fixed it was the database row for the password who has a too short lenght for the hashed password , sorry for the disturbance. Quote Link to comment https://forums.phpfreaks.com/topic/315480-cant-get-the-authentication-to-work-anymore/#findComment-1602139 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.