1. Go to this page and download the library: Download rych/otp 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/ */
rych / otp example snippets
use Rych\OTP\Seed;
// Generates a 20-byte (160-bit) secret key
$otpSeed = Seed::generate();
// -OR- use a pre-generated string
$otpSeed = new Seed('ThisIsMySecretSeed');
// Display secret key details
printf("Secret (HEX): %s\n", $otpSeed->getValue(Seed::FORMAT_HEX));
printf("Secret (BASE32): %s\n", $otpSeed->getValue(Seed::FORMAT_BASE32));
use Rych\OTP\HOTP;
$otpSeed = $userObject->getOTPSeed();
$otpCounter = $userObject->getOTPCounter();
$providedOTP = $requestObject->getPost('otp');
// The constructor will accept a Seed object or a string
$otplib = new HOTP($otpSeed);
if ($otplib->validate($providedOTP, $otpCounter)) {
// Advance the application's stored counter
// This bit is important for HOTP but not done for TOTP
$userObject->incrementOTPCounter($otplib->getLastValidCounterOffset() + 1);
// Now the user is authenticated
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.