PHP code example of enygma / gauth

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

    

enygma / gauth example snippets



$g = new \GAuth\Auth();

// set it to 3 seconds
$g->setRange(3);



eful for creating a new Initialization key if needed
$g = new \GAuth\Auth();
$code = $g->generateCode();
var_dump($code);




$code = 'code-inputted-from-user';

$g = new \GAuth\Auth('your-initialization-code');
$verify = $g->validateCode($code);

if ($verify == true) {
    echo 'User code verified!';
} else {
    echo 'User code invalid!';
}


$holder = '[email protected]';
$name = 'my-app-name';

$g = new \GAuth\Auth('your-initialization-code');
$qrCodeImageData = $g->generateQrImage($holder, $name, 200);

// To use in an image tag:
echo '<img src="data:image/png;base64,'.base64_encode($qrCodeImageData).'"/><br/><hr/>';

// Or just save to a file
file_put_contents('/path/to/qr-file.png', $qrCodeImageData);