PHP code example of pedrosancao / php-otp

1. Go to this page and download the library: Download pedrosancao/php-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/ */

    

pedrosancao / php-otp example snippets


$totp = PedroSancao\OTP\TOTP::create();

// example using Google API, it's recommended to use a local library
$uri = $totp->getUri('[email protected]', 'Issuer Name');
$src = 'https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=' . urlencode($uri);
printf('<img src="%s"/>', $src);
// OR
echo $totp->getSecretReadable();

$secret = $totp->getRawSecret();

$totp = PedroSancao\OTP\TOTP::createRaw($storedSecret);
$totp->verify($inputPassword);

$totp = PedroSancao\OTP\TOTP::create($base32encodedSecret);
// or
$totp = PedroSancao\OTP\TOTP::createRaw($storedSecret);
// or
$totp = PedroSancao\OTP\TOTP::createFromURI($uriFromQrCode);
echo $totp->getPassword();

$totp = PedroSancao\OTP\TOTP::createRaw($storedSecret)->useSha256();