Yet another PHP authentication library.
Install Authsum
via Composer:
$ 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 - checks defined data in an array.
- DoctrineChecker - requires
doctrine/orm
to be installed - EloquentChecker - requires
illuminate/database
to be installed - PdoChecker - uses the
PDO
library
You can also create a new checker by implementing it in CheckerInterface.
Please see CHANGELOG for more information what has changed recently.
$ composer require doctrine/orm illuminate/database --dev
$ composer test
The MIT License (MIT). Please see LICENSE for more information.