Code Monkey home page Code Monkey logo

2fa's Introduction

2FA for Laravel

A One Time Password Authentication package.

Installation

  1. This package publishes a config/hxm2fa.php file. If you already have a file by that name, you must rename or remove it.

  2. You can install the package via composer:

    composer require hxm/2fa
  3. Run the migrations:

    php artisan migrate
  4. You should publish the template views and the config/hxm2fa.php config file with:

    php artisan vendor:publish --provider=HXM2FA\ServiceProvider
    
  • Default config file contents

    // ...
    return [
        'enabled' => true,
        'show_secret' => false,
        'route' => [
            'prefix' => 'user'
        ],
    
        'extend_layout' => 'layouts.app',
    
        'encrypt_secret' => true,
    
        /*customer QR style*/
        'qr_code' => [
            'size' => 192,
            'margin' => 0,
            'background' => [
                'red' => 255, //red the red amount of the color, 0 to 255
                'green' => 255, //green the green amount of the color, 0 to 255
                'blue' => 255 //blue the blue amount of the color, 0 to 255
            ],
            'fill' => [
                'red' => 45, //red the red amount of the color, 0 to 255
                'green' => 55, //green the green amount of the color, 0 to 255
                'blue' => 72 //blue the blue amount of the color, 0 to 255
            ],
        ]
    ];

Basic Usage

  • First, add the HXM2FA\TwoFactorAuthenticatable trait to your User model(s):

      
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use HXM2FA\TwoFactorAuthenticatable;
    
    class User extends Authenticatable
    {
      use TwoFactorAuthenticatable;
    
      // ...
    }
          
  • We provide a Facede with static functions that perform useful functions:

          
    use HXM2FA\Facades\HXM2FA;
    
      // ...
    
      /*to generate Secret*/
      $secret = HXM2FA::generate2FASecret();
    
      
      /*to generate QrCode html*/
      HXM2FA::getQrCode(string $company, string $holder, string $secret)
      
      /*to verify code*/
      HXM2FA::verifyCode(string $secret, string $code)
    
      /*To get instance of \PragmaRX\Google2FA\Google2FA */
      HXM2FA::getGoogle2FA();
    
      // ...
          

Author

HoanXuanMai

2fa's People

Contributors

hoanxuanmai avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.