rougin/authsum

Yet another PHP authentication library.

dev-master / 1.0.x-dev 2020-10-12 02:33 UTC

This package is auto-updated.

Last update: 2024-10-12 11:00:42 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Yet another PHP authentication library.

Installation

Install Authsum via Composer:

$ composer require rougin/authsum

Basic Usage

use Rougin\Authsum\ArrayChecker;
use Rougin\Authsum\Authentication;

$users = array();

$users[] = array('username' => 'rougin', 'password' => 'rougin');
$users[] = array('username' => 'roycee', 'password' => 'roycee');
$users[] = array('username' => 'gutibb', 'password' => 'gutibb');
$users[] = array('username' => 'testtt', 'password' => 'testtt');

$checker = new ArrayChecker($users); // Used for checking the data.

$checker->hashed(false); // Disables checking of hashed password.

$credentials = array('username' => 'rougin', 'password' => 'rougin');

// It validates the credentials first in validate() method.
// Then it returns the success() method if authenticated properly.
// If it fails after checking, then it returns the error() method.
// Class "Authentication" can also be extended, see below.
(new Authentication)->authenticate($checker, $credentials);

Extendable methods

class Authentication extends \Rougin\Authsum\Authentication
{
    protected function success($match)
    {
        // Setting session variables or current user, etc.
    }

    protected function error($type = self::NOT_FOUND)
    {
        // A HTTP 302 redirection, throw exception, etc.
        // If the validation fails, it will go here with a $type of "INVALID"
    }

    protected function validate(array $credentials)
    {
        // CSRF, token checking, etc.
    }
}

Available Checkers

You can also create a new checker by implementing it in CheckerInterface.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer require doctrine/orm illuminate/database --dev
$ composer test

Credits

License

The MIT License (MIT). Please see LICENSE for more information.