PHPackages                             gabrielesbaiz/nova-two-factor - 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. gabrielesbaiz/nova-two-factor

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

gabrielesbaiz/nova-two-factor
=============================

Laravel nova in-dashboard 2FA feature.

1.0.0(1y ago)12.4k↑600%MITPHPPHP ^8.0CI failing

Since Mar 4Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/gabrielesbaiz/nova-two-factor)[ Packagist](https://packagist.org/packages/gabrielesbaiz/nova-two-factor)[ Docs](https://github.com/gabrielesbaiz/nova-two-factor)[ GitHub Sponsors]()[ RSS](/packages/gabrielesbaiz-nova-two-factor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (3)Used By (0)

NovaTwoFactor
=============

[](#novatwofactor)

[![Latest Version on Packagist](https://camo.githubusercontent.com/49495400b9e60f14fe0c9fa4669b26ed5fb47e2f812f360e97e2f926e09cd3ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6761627269656c65736261697a2f6e6f76612d74776f2d666163746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gabrielesbaiz/nova-two-factor)[![Total Downloads](https://camo.githubusercontent.com/73127c4fbb471f10e639d3fae15182c33a56de3d3a01d84537780cfa69533c03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6761627269656c65736261697a2f6e6f76612d74776f2d666163746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gabrielesbaiz/nova-two-factor)

Laravel nova in-dashboard 2FA feature.

Original code from [Visanduma/nova-two-factor](https://github.com/Visanduma/nova-two-factor)

Features
--------

[](#features)

- ✅ Global enable / disable
- ✅ Mandatory / Not mandatory
- ✅ Google 2FA encrypted
- ✅ BancodeQrCode / Google API

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

[](#installation)

You can install the package via composer:

```
composer require gabrielesbaiz/nova-two-factor
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="nova-two-factor-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="nova-two-factor-config"
```

This is the contents of the published config file:

```
return [
    'enabled' => env('NOVA_TWO_FA_ENABLE', true),

    'mandatory' => env('NOVA_TWO_FA_MANDATORY', false),

    'user_table' => 'users',

    'user_id_column' => 'id',

    'connection_name' => env('DB_CONNECTION'),

    /* Encrypt the google secret values saved in database */
    'encrypt_google2fa_secrets' => false,

    /* QR code can be generate using  Google API or inbuilt 'BaconQrCode' package */
    'use_google_qr_code_api' => true,

    'user_model' => App\Models\User::class,

    /* Change visibility of Nova Two Fa menu in right sidebar */
    'showin_sidebar' => true,

    'menu_text' => 'Two FA',

    'menu_icon' => 'lock-closed',

    /* Exclude any routes from 2fa security */
    'except_routes' => [],

    /*
     * reauthorize these urls before access, within given timeout
     * you are allowed to use wildcards pattern for url matching
     */
    'reauthorize_urls' => [
        // 'nova/resources/users/new',
        // 'nova/resources/users/*/edit',
    ],

    /* timeout in minutes */
    'reauthorize_timeout' => 5,
];
```

Usage
-----

[](#usage)

1. Pubish config &amp; migration
2. Use ProtectWith2FA trait in configured model

```
namespace App\Models;

use Gabrielesbaiz\NovaTwoFactor\ProtectWith2FA;

class User extends Authenticatable{

    use ProtectWith2FA;
}
```

3. Add TwoFa middleware to nova config file

```
/*
    |--------------------------------------------------------------------------
    | Nova Route Middleware
    |--------------------------------------------------------------------------
    |
    | These middleware will be assigned to every Nova route, giving you the
    | chance to add your own middleware to this stack or override any of
    | the existing middleware. Or, you can just stick with this stack.
    |
    */

    'middleware' => [
        ...
        \Gabrielesbaiz\NovaTwoFactor\Http\Middleware\TwoFa::class
    ],
```

4. Register NovaTwoFactor tool in Nova Service Provider

```
