PHP Classes

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

Recommend this page to a friend!
  Classes of Slavko Srakocic  >  B12 PHP FW  >  fwphp/glomodul/z_examples/book_video/gallery_powers/authenticate_2way.php  >  Download  
File: fwphp/glomodul/z_examples/book_video/gallery_powers/authenticate_2way.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: 3 months ago
Size: 775 bytes
 

Contents

Class file image Download
<?php
require_once 'connection.php';
$conn = dbConnect('read', 'pdo');
// create key
$key = 'takeThisWith@PinchOfSalt';
$sql = 'SELECT username FROM users_2way
        WHERE username = ? AND pwd = AES_ENCRYPT(?, ?)'
;
// prepare statement
$stmt = $conn->prepare($sql);
// bind variables by passing them as an array when executing statement
$stmt->execute([$username, $password, $key]);
// if a match is found, rowCount() produces 1, which is treated as true
if ($stmt->rowCount()) {
   
$_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.