PHP code example of haikiri / simple-php-totp
1. Go to this page and download the library: Download haikiri/simple-php-totp 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/ */
haikiri / simple-php-totp example snippets
aikiri\SimplePhpTotp\TOTP;
# Generate a secret for storing in the DB.
$secret = TOTP::generateSecret();
# Generate a 6-digit OTP code based on the secret.
$code = TOTP::generate($secret);
echo $secret . PHP_EOL; # Secret for the user. (needs be stored in the user's DB)
echo $code . PHP_EOL; # TOTP-code with which we should compare the code provided by the user from the 2FA-app.
use Haikiri\SimplePhpTotp\TOTP;
$url = TOTP::getTotpUrl(
'GJQTCOBSMI2TGZTD', # OTP-secret (Base32)
'[email protected]', # Username / client identifier
'My Service' # Issuer / organization name
);
echo $url . PHP_EOL; # otpauth://totp/My%20Service:user%40example.com?secret=GJQTCOBSMI2TGZTD&issuer=My%20Service
bash
composer