PHP code example of pragmarx / google2fa-qrcode

1. Go to this page and download the library: Download pragmarx/google2fa-qrcode 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/ */

    

pragmarx / google2fa-qrcode example snippets


use PragmaRX\Google2FAQRCode\Google2FA;
    
$google2fa = new Google2FA();
    
return $google2fa->generateSecretKey();

$inlineUrl = $google2fa->getQRCodeInline(
    $companyName,
    $companyEmail,
    $secretKey
);

$secretKey = $google2fa->generateSecretKey(16, $userId);

$google2fa->setAllowInsecureCallToGoogleApis(true);

$google2fa_url = $google2fa->getQRCodeGoogleUrl(
    'YourCompany',
    $user->email,
    $user->google2fa_secret
);

/// and in your view:

<img src="{{ $google2fa_url }}" alt="">

$secret = $request->input('secret');

$valid = $google2fa->verifyKey($user->google2fa_secret, $secret);

$google2fa->setQrcodeService(new YourService())
          ->getQRCodeInline(
              $companyName,
              $companyEmail,
              $secretKey
          );

$google2fa->setQrcodeService(
    new \PragmaRX\Google2FAQRCode\QRCode\Bacon(
        new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
    )
);

// or 

$google2fa = new Google2FA(
    new Bacon(
        new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
    )
);