Sentry is a PHP 5.3+ fully-featured authentication & authorization system. It also provides additional features such as user groups and additional security features.
Sentry is a framework agnostic set of interfaces with default implementations, though you can substitute any implementations you see fit.
It also provides additional features such as user groups and additional security features:
- Configurable authentication (can use any type of authentication required, such as username or email)
- Authorization
- Activation of user (optional)
- Groups and group permissions
- "Remember me"
- User suspension
- Login throttling (optional)
- User banning
- Password resetting
- User data
- Interface driven - switch out your own implementations at will
There are four simple steps to install Sentry into Laravel 4:
- Add
"cartalyst/sentry": "2.0.*"to therequireattribute of yourcomposer.json(requires you runphp composer.phar updatefrom the command line) - Add
Cartalyst\Sentry\SentryServiceProviderto the list of service providers inapp/config/app.php - Add
'Sentry' => 'Cartalyst\Sentry\Facades\Sentry'to the list of class aliases inapp/config/app.php(optional) - If you'd like to migrate tables, simply run
php artisan migrate --package=cartalyst/sentryfrom the command line. Of course, feel free to write your own migrations which insert the correct tables if you'd like!
{
"require": {
"cartalyst/sentry": "2.0.*"
}
}You heard us say how Sentry is completely interface driven? We have a number of implementations already built in for using Sentry which require the following composer.json file:
{
"require": {
"cartalyst/sentry": "2.0.*",
"illuminate/cookie": "1.2.*",
"illuminate/database": "1.2.*",
"dhorrigan/capsule": "2.0.*",
"illuminate/session": "1.2.*"
}
}Now run php composer.phar update from the command line.
Initializing Sentry requires you pass a number of dependencies to it. These dependencies are the following:
- A hasher (must implement
Cartalyst\Sentry\Hashing\HasherInterface). - A session manager (must implement
Cartalyst\Sentry\Sessions\SessionInterface). - A cookie manager (must implement
Cartalyst\Sentry\Cookies\CookieInterface). - A group provider (must implement
Cartalyst\Sentry\Groups\ProviderInterface). - A user provider (must implement
Cartalyst\Sentry\Users\ProviderInterface). - A throtte provider (must implement
Cartalyst\Sentry\Throttling\ProviderInterface).
Of course, we provide default implementations of all these for you. To setup our default implementations, the following should suffice:
<?php
$hasher = new Cartalyst\Sentry\Hashing\BcryptHasher; // There are other hashers available, take your pick
$illuminateSession = /* Get instance of Illuminate\Session\Store however pleases you */;
$session = new Cartalyst\Sentry\Sessions\IlluminateSession($illuminateSession);
$illuminateCookie = /* Get instance of Illuminate\CookieJar however pleases you */;
$cookie = new Cartalyst\Sentry\Cookies\IlluminateCookie($illuminateCookie);
$groupProvider = new Cartalyst\Sentry\Groups\Eloquent\GroupProvider;
$userProvider = new Cartalyst\Sentry\Users\Eloquent\UserProvider($hasher);
$throttleProvider = new Cartalyst\Sentry\Throttling\Eloquent\ThrottleProvider($userProvider);
$sentry = new Sentry(
$hasher,
$session,
$cookie,
$groupProvider,
$userProvider,
$throttleProvider
);We have plans to add more implementations for each interface which gives you more choice on how you would like to setup Sentry. In the mean-time, if you have would like to share an implementation you have made with us please send through a pull request and we'll be ever so grateful.
We're looking at making:
- A native PHP cookie manager.
- A native PHP session manager (that uses cookies or memcache?).
- Plain PDO based group, user and throttle providers.
Documentation is coming as we near a stable release of Sentry 2.0. Until then, you may check our docs folder, however some of the methods here may have changed and the docs may need updating. Bonus points go to any pull requests to help out with documentation.
