PHPackages                             thinkstudeo/laravel-rakshak - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. thinkstudeo/laravel-rakshak

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

thinkstudeo/laravel-rakshak
===========================

An authentication library for Laravel.

1.1.0(7y ago)08MITPHPPHP &gt;=7.1.3CI failing

Since May 7Pushed 5y agoCompare

[ Source](https://github.com/thinkstudeo/laravel-rakshak)[ Packagist](https://packagist.org/packages/thinkstudeo/laravel-rakshak)[ RSS](/packages/thinkstudeo-laravel-rakshak/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (13)Versions (3)Used By (0)

Rakshak - Two Factor Authentication &amp; Authorization for Laravel 5.7+
========================================================================

[](#rakshak---two-factor-authentication--authorization-for-laravel-57)

[![Latest Version on Packagist](https://camo.githubusercontent.com/da9026518a11f6b93ecb2a06e8dccd8edf4011b0a3113471e7a8cc201eeab6a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7468696e6b73747564656f2f6c61726176656c2d72616b7368616b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thinkstudeo/laravel-rakshak)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a48f1cd9e7214f6621cd21257c7250a0d1f9000e0627d9d027c51c7734e8a8ea/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7468696e6b73747564656f2f6c61726176656c2d72616b7368616b2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/thinkstudeo/laravel-rakshak)[![StyleCI](https://camo.githubusercontent.com/c8562660b6e57e425566811a09a7d6a7221bcde66abcddb40c9359b719f45abe/68747470733a2f2f7374796c6563692e696f2f7265706f732f3138353436373138382f736869656c64)](https://styleci.io/repos/185467188)[![Quality Score](https://camo.githubusercontent.com/62f4b20927b7853aa42e4dc010336e8587736b2db4d9a5ffc8a835582c438256/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7468696e6b73747564656f2f6c61726176656c2d72616b7368616b2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thinkstudeo/laravel-rakshak)[![SymfonyInsight](https://camo.githubusercontent.com/dc12fe0217bffeb1e3478b4fd10a2fb8421756a65232fedd9063ea3333763ef5/68747470733a2f2f696e73696768742e73796d666f6e792e636f6d2f70726f6a656374732f31653961633533322d636133352d343234392d383830302d3265323362373036636564372f6d696e692e737667)](https://insight.symfony.com/projects/1e9ac532-ca35-4249-8800-2e23b706ced7)[![Total Downloads](https://camo.githubusercontent.com/a9269bd4dcff1827f915d4ab9013a754dbbc8d8b8803448e155ae72b8a72e1ed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7468696e6b73747564656f2f6c61726176656c2d72616b7368616b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thinkstudeo/laravel-rakshak)

This package extends the authentication and authorization in a Lavarel application.

- Roles and Abilities for granular authorization.
- Two Factor Authentication functionality.
- Auth views, Blade directives and Route middleware.

Contents
--------

[](#contents)

- [Rakshak - Two Factor Authentication &amp; Authorization for Laravel 5.7+](#rakshak---two-factor-authentication--authorization-for-laravel-57)
    - [Contents](#contents)
    - [Installation](#installation)
    - [Config](#config)
    - [Usage](#usage)
        - [Two Factor Authentication](#two-factor-authentication)
        - [HasRakshak trait](#hasrakshak-trait)
            - [Adding and Retracting Ability to a Role](#adding-and-retracting-ability-to-a-role)
            - [Assigning and Retracting Role to User](#assigning-and-retracting-role-to-user)
            - [Check if the User has role](#check-if-the-user-has-role)
            - [Check if the User has any of given multiple role](#check-if-the-user-has-any-of-given-multiple-role)
            - [Check if the User has ability](#check-if-the-user-has-ability)
            - [Check if the User has any of given multiple abilities](#check-if-the-user-has-any-of-given-multiple-abilities)
        - [Roles and Abilities](#roles-and-abilities)
        - [Route Middleware](#route-middleware)
        - [Blade Directives](#blade-directives)
    - [Changelog](#changelog)
    - [Testing](#testing)
    - [Security](#security)
    - [Contributing](#contributing)
    - [Credits](#credits)
    - [License](#license)

Installation
------------

[](#installation)

```
$ composer require thinkstudeo/laravel-rakshak
```

Then use the artisan command to install/integrate the package with your Laravel application.

```
$ php artisan rakshak:install
```

The artisan command will:

- register the authentication routes
- provide the authentication views (very similar to the `auth:make` command)
- publish the views for managing crud for **Roles, Abilities and Rakshak settings**
- register two middlewares
    - `rakshak.2fa` to verify otp, providing 2fa protection for routes
    - `role` to provide authorization protection for routes
- publish the package config `rakshak.php` to the `config` folder

Finally migrate the database `bash $ php artisan migrate `Migration will alter the `users` table to add

- username
- mobile
- mobile\_verified\_at
- enable\_2fa
- otp\_token
- otp\_expiry
- otp\_channel
- status (for admin to activate/deactivate user)

Migration will add two roles defined in the `roles` key of the config file. Only the User having role `config('rakshak.roles.super_user')` can access the `/rakshak/settings` route to view and edit the Two Factor settings. User having either `config('rakshak.roles.super_user')` or `config('rakshak.roles.authorizer')`

**It is recommended to install the package in a fresh Laravel application**

Config
------

[](#config)

Package config file is published at `config/rakshak.php`.

It allows to enable ***Two Factor Authentication*** - by default it is not enabled. It also allows to replace/modify the notification used for sending the otp and welcome message on registration.

The default notifications are published in the `app/Notifications/Rakshak` directory. You may modify or replace the notifications and then replace the corresponding config key with the FQCN of your new notification.

```
