This is a login script that I wrote. I used crypt() for storing hashed passwords.
<?php
$db = new mysqli ('localhost','bla','bla','bla');
if(isset($_POST['submit_form'])){
$username = $_POST['username'];
$password = $_POST['password'];
$username2 = mysqli_real_escape_string($db, $_POST['username']);
$sql = "SELECT * FROM users WHERE username=:username";
$stmt = $db->prepare($sql);
$stmt->bindValue(':username',$username,PDO::PARAM_STR);
if($stmt->execute())
{
if($stmt->rowCount() == 1)
{
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (crypt($password, $row['pass']) === $row['pass'])
{
session_start();
$_SESSION['user'] = $username2;
$_SESSION['notification'] = 'blabla';
header('location:/someplace');
}
else
{
session_start();
$_SESSION['not'] = 'wrong';
header('location:/someplace');
}
}
else
{
session_start();
$_SESSION['not'] = 'wrong';
header('location:/someplace');
}
}
}
else {
header('location:/ss');
}
?>
I'm trying to resolve the problem for a long time. But it is not yielding any result. Searched through many answers, tried 5-6 different methods. Still not working. I'm using PDO for the first time. Before this, I was using only mysqli_real_escape_string() and it was working fine.