PHP code example of phant / otp

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

    

phant / otp example snippets


use Phant\DataStructure\Key\Ssl as SslKey;
use Phant\Otp\Service\Request as Service;
use App\OtpRepository;
use App\OtpSender;

// Config

$otpRepository = new OtpRepository();
$otpSender = new OtpSender();
$sslKey = new SslKey($privateKey, $publicKey);


// Build service

$service = new Service(
	$otpRepository,
	$otpSender,
	$sslKey
);


// OTP context transmitted to sender
$payload = [
	'email' => '[email protected]',
];

$requestToken = $service->generate(
	$payload
);

use Phant\Error\NotCompliant;

// Request token obtained previously
$requestToken = '...';

// Obtain Otp from user
$otp = '123456';

try {
	$payload = $service->verify(
		$requestToken,
		$otp
	);
} catch (NotCompliant $e) {
	$numberOfAttemptsRemaining = $otpService->getNumberOfRemainingAttempts(
		$requestToken
	);
}