1
I have a problem that always falls independently in the error line Incorrect Password, this script was in mysqli and I am trying to pass to PDO. What could be wrong?
<?php
session_start();
include 'db.php';
$pdo = pdo_connect_mysql();
if ( !isset($_POST['usuario'], $_POST['password']) ) {
die ('Please fill both the username and password field!');
}
if ($stmt = $pdo->prepare('SELECT id,password FROM users WHERE usuario = ?')) {
$stmt->execute([$_POST['usuario']]);
$result=$stmt->fetchALL(PDO::FETCH_OBJ);
}
if ($stmt->rowCount() > 0) {
$stmt->bindParam(1, $id, PDO::PARAM_INT);
$stmt->bindParam(2, $password, PDO::PARAM_STR, 100);
$stmt->fetch();
if (password_verify($_POST['password'], $password)) {
session_regenerate_id();
$_SESSION['loggedin'] = TRUE;
$_SESSION['usuario'] = $_POST['usuario'];
$_SESSION['id'] = $id;
echo 'Welcome ' . $_SESSION['usuario'] . '!';
} else {
echo 'Incorrect password!';
}
} else {
echo 'Incorrect username!';
}
die();
At what point are you making the $password assignment coming from the database?
– Lucas Emanuel