require_once('php-auth/Auth.php'); $auth = new Auth(); if($_SERVER['REQUEST_METHOD'] == 'POST') { $username = $_POST['username']; $password = $_POST['password']; if($auth->login($username, $password)) { header('Location: /dashboard.php'); exit; } else { echo 'Invalid username or password'; } }
require_once('php-auth/Auth.php'); $auth = new Auth(); if($_SERVER['REQUEST_METHOD'] == 'POST') { $username = $_POST['username']; $password = $_POST['password']; if($auth->login($username, $password)) { $auth->sendTwoFactorCode($username); header('Location: /verify.php'); exit; } else { echo 'Invalid username or password'; } } if($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['code'])) { $username = $_SESSION['username']; $code = $_GET['code']; if($auth->verifyTwoFactorCode($username, $code)) { $_SESSION['authenticated'] = true; header('Location: /dashboard.php'); exit; } else { echo 'Invalid code'; } }PHP Auth is a package library developed by PHP developers and it can be installed using Composer.