File: fwphp/glomodul/z_examples/book_video/gallery_powers/authenticate.php

Recommend this page to a friend!
  Classes of Slavko Srakocic  >  B12 PHP FW  >  fwphp/glomodul/z_examples/book_video/gallery_powers/authenticate.php  >  Download  
File: fwphp/glomodul/z_examples/book_video/gallery_powers/authenticate.php
Role: Example script
Content type: text/plain
Description: Example script
Class: B12 PHP FW
Manage database records with a PDO CRUD interface
Author: By
Last change:
Date: 1 month ago
Size: 749 bytes
 

Contents

Class file image Download
<?php
require_once 'connection.php';
$conn = dbConnect('read', 'pdo');
// get the username's hashed password from the database
$sql = 'SELECT pwd FROM users WHERE username = ?';
// prepare statement
$stmt = $conn->prepare($sql);
// pass the input parameter as a single-element array
$stmt->execute([$username]);
$storedPwd = $stmt->fetchColumn();
// check the submitted password against the stored version
if (password_verify($password, $storedPwd)) {
   
$_SESSION['authenticated'] = 'Jethro Tull';
   
// get the time the session started
   
$_SESSION['start'] = time();
   
session_regenerate_id();
   
header("Location: $redirect");
    exit;
} else {
   
// if not verified, prepare error message
   
$error = 'Invalid username or password';
}

For more information send a message to info at phpclasses dot org.