pmill / php-auth
A simple authentication library
0.2.3
2015-05-30 13:55 UTC
Requires
- aura/session: ^2.0
- ircmaxell/password-compat: ^1.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2019-09-18 22:52:25 UTC
README
Introduction
This package contains a simple framework agnostic PHP authentication library.
Installation
Installing via Composer
The recommended way to install php-auth is through Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest version of php-auth:
composer.phar require pmill/php-auth
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
Usage
Implement the AuthUser interface on your existing user class. Make sure when you set the user's password, you hash it first.
class User implements \pmill\Auth\Interfaces\AuthUser
{
public function setPassword($password)
{
$passwordHelper = new \pmill\Auth\Password;
$this->password = $passwordHelper->hash($password);
}
/**
* The rest of your user class
*/
}
Create your user instance
$user = new User();
$user->setId(1);
$user->setUsername('username');
$user->setPassword('password');
Attempt the login
$auth = new \pmill\Auth\Authenticate;
try {
$auth->login($user, 'password');
echo 'login succeeded';
}
catch(\pmill\Auth\Exceptions\PasswordException $e) {
echo 'login failed, incorrect password';
}
Version History
0.2.3 (30/05/2015)
- Added customisable session key
0.2.2 (25/05/2015)
- Separated out the two factor authentication code in Authentication.php into a separate injectable class
0.2.1 (24/05/2015)
- Fixed a bug where we were coding against the implementation of PasswordHelper rather than the interface
0.2.0 (23/05/2015)
- Separated Auth class into Authentication and Password
0.1.1 (23/05/2015)
- Added unit tests
0.1.0 (22/05/2015)
- First public release of php-auth
Copyright
php-auth Copyright (c) 2015 pmill (dev.pmill@gmail.com) All rights reserved.