PHP code example of williameggers / php-totp
1. Go to this page and download the library: Download williameggers/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/ */
williameggers / php-totp example snippets
use williameggers\phptotp\{Base32,Totp};
# Generate a new secret key
# Note: generateSecret returns a string of random bytes. It must be base32 encoded before displaying to the user. You should store the unencoded string for later use.
$secret = Totp::generateSecret(16);
# Display new key to user so they can enter it in Google Authenticator or Authy
echo Base32::encode($secret);
# Generate the current TOTP key
# Note: generateToken takes a base32 decoded string of bytes.
$key = (new Totp())->generateToken($secret)
# Check if user submitted correct key
if ($user_submitted_key !== $key) {
exit();
}
$ ./generate.php
Enter secret key: turtles
Token: 338914
$