I am having many problems and I do not know how to solve it. I tell you about the problems that are emerging.
The login fails random users, that is, one day it works or another one does not and so ... strange. users that I have changed the pass directly in the database without going through the registry. My user always works, but the one of the others .... no.I do not understand it, I am going to leave my code, in case you see some type of failure. I have to say that this is already in a published website. Obviously I changed the data when doing the database to the database.
<?php session_start();
if (isset ($_SESSION['usuario'])){
header('Location: ../php/home.php');
}
$errores = '';
if ($_SERVER['REQUEST_METHOD'] =='POST') {
$email = filter_var(strtolower($_POST['email']), FILTER_SANITIZE_STRING);
$password = $_POST['password'];
$password = hash('sha512', $password);
try {
$conexion = new PDO('mysql:host=localhost;dbname=base_de_datos', 'root', ' ') ;
// la conexión a la base de datos se hace bien.
} catch (PDOException $e) {
echo "Error". $e->getMessage();;
}
$statement = $conexion->prepare ('SELECT * FROM usuarios WHERE email = :email AND pass = :password');
$statement->execute(array(
':email'=> $email,
':password'=>$password
));
$resultado = $statement->fetch();
if ($resultado !==false) {
$_SESSION ['usuario'] = $email;
header('Location: ../php/home.php');
}else {
$errores= '<li style="color:red;"> Tu e-mail o contraseña no son correctos</li>';
}
}
?>
<form class="text-center formulario" style="color: #757575;" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="POST" name="login">
<!-- Email -->
<div class="md-form">
<input type="email" id="materialLoginFormEmail" class="form-control" name="email">
<label for="materialLoginFormEmail">E-mail</label>
</div>
<!-- Password -->
<div class="md-form">
<input type="password" id="materialLoginFormPassword" class="form-control" name="password">
<label for="materialLoginFormPassword">Contaseña</label>
</div>
<div class="d-flex justify-content-around">
<div>
<!-- Forgot password -->
<a href=""></a>
</div>
</div>
<!-- Sign in button -->
<div class="text-center mt-4">
<button class="btn btn-warning btn-lg mt-4" onclick="login.submit()">Login</button>
</div>
<br>
<br>
<?php if(!empty($errores)):?>
<div class="error">
<ul>
<?php echo $errores;?>
</ul>
</div>
<?php endif;?>
<br>
<br>
<!-- Register -->
<p>¿No eres miembro?
<a href="php/registro.php">Registrate</a>
</p>
</div>
</div>
</form>