1. Go to this page and download the library: Download kayon-ariel/totp-php 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/ */
kayon-ariel / totp-php example snippets
use TotpPhp\Totp;
// Create a new TOTP instance
$ga = new Totp();
// Generate a secret key
$secret = $ga->createSecret();
echo "Secret is: " . $secret . "\n\n";
// Generate a TOTP code based on the secret
$oneCode = $ga->getCode($secret);
echo "Checking Code '$oneCode' and Secret '$secret':\n";
// Verify the TOTP code against the secret
$checkResult = $ga->verifyCode($secret, $oneCode);
if ($checkResult) {
echo 'OK';
} else {
echo 'FAILED';
}
$userInputCode = '123456'; // Example user input
$isValid = $ga->verifyCode($secret, $userInputCode);
if ($isValid) {
echo "The TOTP code is valid!";
} else {
echo "The TOTP code is invalid!";
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.