1. Go to this page and download the library: Download metarush/otp-auth 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/ */
if (!$auth->authenticated()) {
$rememberedUsername = $auth->rememberedUsername();
if (null !== $rememberedUsername)
$auth->login($rememberedUsername);
}
_POST) {
$username = $_POST['email'];
// check if username exists
if (!$auth->userExist($username))
exit('User does not exist');
// remember username for next page (otp.php)
setcookie('username', $username);
// send OTP to user's email
$otp = $auth->generateToken(5);
$auth->sendOtp($otp, $username);
// redirect to OTP page
header('location: otp.php');
}
_POST) {
$otp = $_POST['otp'];
$username = $_COOKIE['username'];
// remember username in browser if user wants to
if (isset($_POST['remember']))
$auth->remember($username);
// check if OTP is valid
if (!$auth->validOtp($otp, $username))
exit('Invalid OTP');
// login username
$auth->login($username);
echo 'OTP is valid';
// redirect to your restricted page
}