0% found this document useful (0 votes)
21 views2 pages

Mooyaa

Uploaded by

Stephen Mwaniki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Mooyaa

Uploaded by

Stephen Mwaniki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

<?

php

// Establish a connection to the database

$host = "localhost";

$username = "root";

$password = "";

$dbname = "my_database";

try {

$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

} catch (PDOException $e) {

die("Connection failed: " . $e->getMessage());

// Retrieve the email and password entered by the user

$email = $_POST['email'];

$password = $_POST['password'];

// Hash the password

$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Query the database to retrieve the user with the given email

$sql = "SELECT * FROM users WHERE email = :email";

$stmt = $pdo->prepare($sql);

$stmt->execute(['email' => $email]);

$user = $stmt->fetch();
// Verify the hashed password against the user's stored password

if (password_verify($password, $user['password'])) {

// Passwords match - log in the user

session_start();

$_SESSION['user_id'] = $user['id'];

header("Location: account.php");

exit();

You might also like