1. Go to this page and download the library: Download tzsk/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/ */
// Generate -
Otp::digits(8)->generate($unique_secret); // 8 Digits, Default expiry from config
Otp::expiry(30)->generate($unique_secret); // 30 min expiry, Default digits from config
Otp::digits(8)->expiry(30)->generate($unique_secret); // 8 digits, 30 min expiry
// The generate method above can be swapped with other generator methods. Ex -
Otp::make($unique_secret);
Otp::create($unique_secret);
// Match - (Different Runtime)
// For the first example above
Otp::check($otp, $unique_secret); // -> false
Otp::digits(8)->check($otp, $unique_secret); // -> true
// For the second example above
Otp::check($otp, $unique_secret); // -> false
Otp::expiry(30)->check($otp, $unique_secret); // -> true
// For the third example above
Otp::check($otp, $unique_secret); // -> false
Otp::digits(8)->expiry(30)->check($otp, $unique_secret); // -> true
/**
* You will need a directory in your filesystem where the package can store data.
* Ensure you restrict access to this directory and its files using your web server configuration (Apache or Nginx).
*/
// Let's assume the directory you created is `./otp-tmp`
$manager = otp('./otp-tmp');
/**
* Default properties -
* $digits -> 4
* $expiry -> 10 min
*/
$manager->digits(6); // To change the number of OTP digits
$manager->expiry(20); // To change the mins until expiry
$manager->generate($unique_secret); // Will return a string of OTP
$manager->match($otp, $unique_secret); // Will return true or false.