SQL Adapter

Authenticate against a database table where users’ passwords are stored using PHP’s bcrypt hashing and the PASSWORD_DEFAULT algorithm. Under the hood, it uses password_verify().

// user table in database //
+----------+-------------+------------+---------------------+
| username | fullname    | email      | bcryptpass          |
|----------+-------------+------------+---------------------|
| juser    | Joe User    | juser@...  | $2y$.............   |
+----------+-------------+------------+---------------------+
<?php

use Vespula\Auth\Session\Session;
use Vespula\Auth\Auth;
use Vespula\Auth\Adapter\Sql;

$session = new Session();
$dsn = 'mysql:dbname=mydatabase;host=localhost';
$pdo = new \PDO($dsn, 'dbuser', '********');

// $cols array must have a 'username' and 'password' element.
// You can use an alias if needed. See below.
// This data (except username and password) will populate the `getUserdata()` array
$cols = [
    'username',
    'bcryptpass'=>'password', // alias
    'fullname'=>'full_name' // alias
    'email'
];
$from = 'user';
$where = 'active=1'; // optional

$adapter = new Sql($pdo, $from, $cols, $where);
$auth = new Auth($adapter, $session);