Session does not open when logging in

Asked

Viewed 66 times

0

I’m changing an old admin project, I was able to switch passwords from sha1 to password_hash, but the session no longer opens when logging in. What could be happening? I have searched and found no solution.

$sql = "SELECT `id`, `nome`, `nivel` FROM `usuarios` WHERE (`usuario` = '". $usuario ."') AND (`ativo` = 1) LIMIT 1";
$query = mysqli_query($conexao, $sql);

$senhabd = mysqli_fetch_assoc($query);
if(password_verify($senha, $senhabd['senha'])){

if (mysqli_num_rows($query) != 1) {

echo "<script>document.location='../login.php'; alert('Login Inválido! Tente novamente.')</script>";
     exit;

} else {

    $resultado = mysqli_fetch_assoc($query);

    if (!isset($_SESSION)) session_start();

  • 1

    besides id, name, level, would not have to put also 'password' in the query?

  • @Leocaracciolo When it was sha1 it was in the query, however password_verify is boolean, I do not know how to compare inside the query.

  • @Lucasguse, you mentioned that you switched passwords to sha1, how did you do this process? You implemented the hash from the PHP password_hash method?

  • @Diegomiranda This, in the registration of the users I changed the password to password_hash and it worked all right, in the login it accepts and redirects. But the pages have login check and end up giving error, it seems to me that the Session is not open.

  • This is the code that goes on the pages to check the login?

  • @Lucasguse, from this updated code snippet, is the user really obtained to compare passwords? The verification of the number of records obtained should not be found before the verification of passwords?

  • @Tiagoa this is the login validation, the pages is different.

  • @Diegomiranda, I was able to solve :) I was having a problem calling the password in the database, I was comparing it to the first password I had in the comic instead of taking the user’s password. Thank you.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.