I have a login system in php. In my database I have only two people registred and the login system only works with the first one. I have alredy check the form but it doesn't work. Thank you
<?php
try{
$conexion = new PDO("mysql:host=localhost; dbname=pruebas_login" , 'root', '' );
$conexion->exec('SET NAMES utf8');
$conexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM USUARIOS_PASS WHERE USUARIOS= :login AND PASSWORD= :password" ;
$resultado = $conexion->prepare($sql);
$usuario = htmlentities(addslashes($_POST['username']));
$password = htmlentities(addslashes($_POST['password']));
$resultado->bindValue(":login", $usuario);//bindValue = bind_param solo que con marcadores
$resultado->bindValue(":password", $password);
$resultado->execute();
$numero_registro = $resultado->rowCount();
if($numero_registro != 0){
session_start();
$_SESSION["usuario"]=$_POST['username'];
header("location:usuarios_registrados.php");
}else{
header("location:login.php");
}
}catch(Exception $e){
die("Error". $e->getMessage());
}
?>
The code should look like this this after $resultado->execute(). But make it fit with your style. I just add a fetch and save it as $data then use it as auth.
$data = $resultado->fetch();
if ($resultado->rowCount > 0)
{
if (password_verify($password, $data['password']))
{
$_SESSION['user_session'] = $data['username'];
return true;
}
}