sFire\OTP\Driver\TOTP is a driver for sFire\OTP\OTP.
To set-up the TOTP driver, you need to inject the driver into a new instance of sFire\OTP\OTP. You can do so by calling the setDriver method.
use sFire\OTP\OTP;
$otp = new OTP();
$otp -> setDriver('totp');
After setting the driver, you can create a time-based password
$otp = new OTP();
$otp -> setDriver('totp');
$otp -> setSecret('ABCDEFGHIJKLMNOP');
$password = $otp -> now();
var_dump($password); //Outputs similar to "574252"
The now method will use the current timestamp, but you may also set the timestamp yourself by calling the timestamp method to create a time-based on time password:
$password = $otp -> timestamp(time());
You may use the verify method to verify if a given password is correct. This method takes two parameter. The first argument is the time-based one time password as an integer. The second optional parameter is an unix timestamp, if you want to verify an old or even a password in the future.
$otp = new OTP();
$otp -> setDriver('totp');
$otp -> setSecret('ABCDEFGHIJKLMNOP');
$password = $otp -> now();
$otp -> verify($password); //Outputs boolean true
$otp -> verify($password, time()); //Outputs boolean true
You may set a couple of options:
You can set the expiration of an password in seconds by using the setInterval method:
$otp -> setInterval(40);
Even the amount of digits the password needs to contain can be set with the setDigits method:
$otp -> setDigits(8);
You may set the used algorithm with the setAlgorithm method:
$otp -> setAlgorithm('sha256');
You can use the provision url to create a QR code for mobile deviced to scan and add the account and secret automatically.
$otp = new OTP();
$otp -> setDriver('totp');
$otp -> setSecret('ABCDEFGHIJKLMNOP');
$url = $otp -> getProvisioningUrl('sFire');
var_dump($url); //Output similair to "otpauth://totp/sFire?secret=ABCDEFGHIJKLMNOP"