PHP code example of hxm / 2fa

1. Go to this page and download the library: Download hxm/2fa library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hxm / 2fa example snippets


    // ...
    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
            ],
        ]
    ];
    

      
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use HXM2FA\TwoFactorAuthenticatable;
    
    class User extends Authenticatable
    {
      use TwoFactorAuthenticatable;
    
      // ...
    }
          
    

          
    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();
    
      // ...
          
    
bash
    php artisan migrate
    
bash
    php artisan vendor:publish --provider=HXM2FA\ServiceProvider