### Instantiate Google2FA Directly
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Instantiate the Google2FA class directly to begin using its features. This is the primary way to get started with the package.
```php
use PragmaRX\Google2FA\Google2FA;
$google2fa = new Google2FA();
return $google2fa->generateSecretKey();
```
--------------------------------
### Run PHPUnit Tests
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Execute the package's tests using Composer and PHPUnit. Ensure Composer is installed and the package dependencies are managed.
```bash
composer test
```
--------------------------------
### Set OTP Window for Verification
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Verifies a key using a specified window size. A window of 0 means the OTP is valid for 30 seconds, while a window of 2 makes it valid for 120 seconds.
```php
$isValid = $google2fa->verifyKey($seed, $key, 4);
```
--------------------------------
### Render QR Code with Simple QrCode
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Renders a QR code using the Simple QrCode package, suitable for printing.
```php
{!! QrCode::size(100)->generate($google2fa->getQRCodeUrl($companyName, $companyEmail, $secretKey)); !!}
Scan me to return to the original page.
```
--------------------------------
### Generate QR Code Image with Bacon/QRCode
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Generates a QR code image using Bacon/QRCode and encodes it as a base64 string for display.
```php
getQRCodeUrl(
'pragmarx',
'google2fa@pragmarx.com',
$google2fa->generateSecretKey()
);
$writer = new Writer(
new ImageRenderer(
new RendererStyle(400),
new ImagickImageBackEnd()
)
);
$qrcode_image = base64_encode($writer->writeString($g2faUrl));
?>
```
--------------------------------
### Verify Google Authenticator Key with Window
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Validates a provided key against the user's secret, considering a window of past and future keys to account for clock drift. Defaults to a window of 1.
```php
$secret = $request->input('secret');
$window = 8; // 8 keys (respectively 4 minutes) past and future
$valid = $google2fa->verifyKey($user->google2fa_secret, $secret, $window);
```
--------------------------------
### Set OTP Window Globally
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Sets the window property for OTP validity. This determines how many 30-second cycles an OTP will be considered valid.
```php
$secretKey = $google2fa->setWindow(4);
```
--------------------------------
### Display QR Code Data URI with Endroid
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Displays a QR code generated as a data URI in an HTML view.
```php
{!! $google2fa_url !!}
Scan me to return to the original page.
```
--------------------------------
### Generate Secret Key with Prefix
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/README.md
Generates a secret key with a specified prefix. The prefix length must be compatible with base 32 conversion and the secret key's power-of-2 length.
```php
$prefix = strpad($userId, 10, 'X');
$secretKey = $google2fa->generateSecretKey(16, $prefix);
```
--------------------------------
### Original GPLv3 License Text
Source: https://github.com/antonioribeiro/google2fa/blob/9.x/RELICENSED.md
This block contains the full text of the GNU General Public License v3, under which the Google2FA package was originally licensed. It outlines the terms for redistribution and modification.
```php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see