I have made an register script with md5 but now I have to log in with it. I have tried many things but it didn't work.
This is my code:
if(isset($_POST['sub'])) {
include_once("Connect.php");
$username = mysqli_real_escape_string($dbcon,$_POST['username']);
$password = mysqli_real_escape_string($dbcon,$_POST['password']);
$password = md5($_POST['password']);//hashing pass
$sql = "SELECT * FROM users WHERE userName = '{$username}' and userPassword = '{$password}'";
$query = mysqli_query($dbcon, $sql) or die(mysqli_error($dbcon));
$count = mysqli_num_rows($query);
if ($count > 1)
{
$row = mysqli_fetch_row($query);
$userId = $row[0]; // takes id from DataBase
$dbUsername = $row[1]; // takes username from DataBase
$dbPassword = $row[2]; // takes userpass from DataBase
$_SESSION['password'] = $dbPassword;
$_SESSION['username'] = $dbUsername;
$_SESSION['id'] = intval($userId);
$_SESSION['login'] = TRUE; // if username and pass are corrects it logs in
header('location: login.php');
die(); // using die() after header()
}
else {
echo "incorrect username or password.";
}
}
thanks all for your comments.
the solution:
$inlogcrypt = md5($password);
$sql = "SELECT * FROM users WHERE userName = '".$username."' and userPassword = '".$inlogcrypt."'";