I'm try to use hash from PHP to encrypt my password save to database. This is my login code:
$email=$_POST['email'];
$password=$_POST['password'];
$sql ="SELECT user_email FROM tbl_user WHERE user_email=:email ";
$query= $dbh -> prepare($sql);
$query-> bindParam(':email', $email, PDO::PARAM_STR);
$query-> execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
if($query->rowCount() > 0)
{
if(password_verify($password, $results["user_password"]))
{
$_SESSION['signin']=$_POST['email'];
$currentpage=$_SERVER['REQUEST_URI'];
echo "<script type='text/javascript'> document.location = '$currentpage'; </script>";
}
else
{
echo "<script>alert('Invalid Details');</script>";
}
} else{
echo "<script>alert('Invalid Details');</script>";
}
and this is my signup code :
$user_fullname=$_POST['fullname'];
$user_email=$_POST['email'];
$user_phonenumber=$_POST['telephone'];
$hashToStoreInDb = password_hash($_POST['password'], PASSWORD_DEFAULT);
$sql="INSERT INTO tbl_user(user_email,user_fullname,user_phonenumber,user_password) VALUES(:user_email,:user_fullname,:user_phonenumber,:hashToStoreInDb)";
$query = $dbh->prepare($sql);
$query->bindParam(':user_email',$user_email,PDO::PARAM_STR);
$query->bindParam(':user_phonenumber',$user_phonenumber,PDO::PARAM_STR);
$query->bindParam(':user_fullname',$user_fullname,PDO::PARAM_STR);
$query->bindParam(':hashToStoreInDb',$hashToStoreInDb,PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if($lastInsertId)
{
echo "<script>alert('Something went wrong. Please try again');</script>";
}
else
{
echo "<script>alert('Registration successfully. Now you can Sign In');</script>";
}
I can signup and save the data in my database , after sign up i don't to verify password for login and i stuck at login. Please help me if i have wrong code or any suggestion code to modify my code. Thanks for help