rougin / authsum
又一个PHP身份验证库。
dev-master / 1.0.x-dev
2020-10-12 02:33 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: ~4.2|~5.7
- scrutinizer/ocular: ~1.1.0
This package is auto-updated.
Last update: 2024-09-12 10:45:24 UTC
README
又一个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. } }
可用的检查器
- ArrayChecker - 检查数组中定义的数据。
- DoctrineChecker - 需要
doctrine/orm
已安装 - EloquentChecker - 需要
illuminate/database
已安装 - PdoChecker - 使用
PDO
库
您还可以通过实现CheckerInterface来创建一个新的检查器。
变更日志
请参阅CHANGELOG以获取更多关于最近更改的信息。
测试
$ composer require doctrine/orm illuminate/database --dev
$ composer test
鸣谢
许可协议
MIT许可(MIT)。请参阅LICENSE获取更多信息。