rougin/authsum

又一个PHP身份验证库。

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

This package is auto-updated.

Last update: 2024-09-12 10:45:24 UTC


README

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

又一个PHP身份验证库。

安装

通过Composer安装Authsum

$ composer require rougin/authsum

基本用法

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);

可扩展的方法

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.
    }
}

可用的检查器

您还可以通过实现CheckerInterface来创建一个新的检查器。

变更日志

请参阅CHANGELOG以获取更多关于最近更改的信息。

测试

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

鸣谢

许可协议

MIT许可(MIT)。请参阅LICENSE获取更多信息。