Another night, another question!
I have created a log in page which works fine if the passwords are in plain text.
The issue I have is that my sign up form uses password_hash to enter an encrypted password to the table.
My current scripts are below.
Sign Up Script
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
Log In Script
<?php
session_start();
if(isset($_POST['email'], $_POST['password'])){
require('../../../private_html/db_connection/connection.php');
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $conn->prepare("SELECT * FROM user_accounts WHERE email=:email AND password=:password");
$query->bindParam(':email', $_POST['email']);
$query->bindParam(':password', $_POST['password']);
$query->execute();
if($row = $query->fetch()){
$_SESSION['email'] = $row['email'];
$_SESSION['first_name'] = $row['first_name'];
header("Location: ../../myaccount/myaccount.php");
}
else {header("Location:../../login/login.php ");}
}
?>
I have a couple of questions on this one:
- Where do I put
password_verify
in my login script? - Instead of having to type in multiple
$_SESSION['xxx'] = $row['xxx'];
to display the users details on the 'My Account' page, how can I utilise the$results = $stmt->fetch(PDO::FETCH_ASSOC);
method that I have read about?
Many thanks in advance,
CyrilWalrus