error comparing sha1 in php

Asked

Viewed 84 times

2

I am making a login system but when comparing the password that the user typed with the one in the error database. When the user registers on the system applies two sha1 guy : sha1(sha1($_POST['senha']));

But when I compare some error, because it is not the same code saved, I do not know if it is something in the code, follow the code, I thank you..

  if(isset($_POST['email']) && strlen($_POST['email']) > 0){

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

   $link = DBConnect();
   $_SESSION['email'] = $link->escape_string($_POST['email']);
   $_SESSION['senha'] = sha1(sha1($_POST['senha']));


$UserCheck = DBRead( 'usuarios', "WHERE email = '". $_POST['email']."'", 'id,email,senha');  
var_dump($UserCheck);
$id = (string)$UserCheck[0]['id'];
$email = (string)$UserCheck[0]['email'];
$senha = (string)$UserCheck[0]['senha'];
var_dump($id.'</br></br>'.$email.'</br>'.$senha);
$senhasession = sha1(sha1($_SESSION['senha']));
var_dump($senhasession);
  if ($email)
    if($senha == $senhasession){
      $_SESSION['usuario'] = $id;
      //echo "<script>location.href='admin.php'</script>";
      echo $id;
    }
    else{
      //echo "<script>alert('Senha incorreta!');</script>";
    }

  else{
    echo "<script>alert('Email incorreto!');</script>";
  }

}

  • gave some error in the editor in the forum pq I typed the if correctly

  • What’s the point of using sha1 2x?

1 answer

3


In this Techo

$senhasession = sha1(sha1($_SESSION['senha']));

modify to

$senhasession = $_SESSION['senha'];

The reason is that in a previous line is already applying the "double sha1"

$_SESSION['senha'] = sha1(sha1($_POST['senha']));
  • It worked out! Thanks partner!

Browser other questions tagged

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