0

Upon registering a new user, the code uses BCRYPT and MD5 to create a hash, like this:

$password = $mysqli->escape_string(password_hash($_POST['password'], 
PASSWORD_BCRYPT));
$hash = $mysqli->escape_string( md5( rand(0,1000) ) );

Once user name, password, and hash are in the SQL database, I want to verify the password. The problem is that the code below is comparing the hashed password to the password typed into the form...

How do I compare the password typed into the form to the hashed password stored in the database?

I have the following code:

function getLogin($conn) {
  if (isset($_POST['loginSubmit'])){


  $email = $_POST['email'];
  $password = $_POST['password'];

  $sql = "SELECT * FROM users WHERE email='$email' AND password='$password'" ;
  $result = mysqli_query($conn, $sql);
  if(mysqli_num_rows($result) == 1) {
    if($row = $result->fetch_assoc()) {
      $_SESSION['id'] = $row['id'];
      $_SESSION['email'] = $row['email'];

      header("Location: indexcomments_merge.php?logiinsuccess");
      exit();
    }
  } else {
      header("Location: indexcomments_merge.php?logiinfailed");
      exit();
   }
  } 
}
Ben
  • 9
  • 5

1 Answers1

-1

Its just simple you have to convert password from form to MD5 to compare it.

$password=md5($_POST['password']);

I hope it will help you.. Thank You.

Anadkat Bhavik
  • 111
  • 1
  • 6