Today we are going to develop Custom SlimPHP Authentication Scaffolding secured login system. Codes are available at GitHub.
Slim PHP custom authentication scaffolding
git clone this URL for the application
https://github.com/lanwilds/slimauthentication
Pre-Requirements Slim PHP
Slim PHP is a micro-framework developed using PHP, since it is a micro framework there is
no authentication scaffolding in Slim PHP so everything should start from the scracth we have articles on slimphp how to start and all the stuff relatedet it so, if you dont understand what slimPhp is then please do read our RESTful API with SlimPHP.
Slim Authentication
What are the technologies?
- Slim PHP
- Laravel-ORM Eloquent for DB models
- Symfony-Twig views
- Slim Flash and Slim CSRF protection
- RESPECT validation service
What and all in the Application?
- Login Panel
- Register Panel
- Password Change Panel
How secured Slim PHP authentication is?
This authentication system was custom developed with slimPHP DI container or dependancy injection container where all the data and functions classes binded with a container class where you can easily invoke the container for getting class methods.
this application takes login credentials i.e email and password and matches with the database. if match found it sets the middleware which is responsible for authenticating users
your secured routes should have the Auth middleware where the routes only be accessed by the authenticated users.
Open up routes.php file located inside App Folder and you have to register routes at there
//Authentication Routes
$app->group(”, function() {
$this->get(‘/account/signout’, ‘AuthController:getLogOut’)->setName(
‘auth.logout’);
$this->get(‘/account/password/change’, ‘PasswordController:getChange
Password’)->setName(‘auth.password.change’);
$this->get(‘/dashboard’, ‘DashController:index’)->setName(‘dash’);
})->add(new AuthMiddleware($container));
The above routes are has the instance of Authentication middleware so these are the protected routes.
//Guest Routes
$app->group(”, function(){
$this->get(‘/’, ‘HomeController:index’)->setName(‘home’);
$this->post(‘/account/login’, ‘AuthController:postLogIn’)->setName(‘
auth.login’);
$this->get(‘/account/signin’, ‘AuthController:getSignIn’)->setName(‘
auth.signin’);
})->add(new GuestMiddleware($container));
These are guest routes where only non authenticated users can visit these URL’s. however concidering middlewares you can create your own routes. The Auth folder where main authenticationfiles are exists you can check that. About the Database Models and Validation system and Controllers. we have articles reguarding that please do read.
if you find any problems you can ping me I’ll solve your queries. comment down.
please keep visiting ..