1. Go to this page and download the library: Download triopsi/simple-two-factor 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/ */
triopsi / simple-two-factor example snippets
public function bootstrap(): void {
parent::bootstrap();
$this->addPlugin('SimpleTwoFactor');
}
use SimpleTwoFactor\Middleware\TwoFactorMiddleware;
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
$middlewareQueue
->add(new ErrorHandlerMiddleware(Configure::read('Error')))
->add(new AssetMiddleware())
->add(new RoutingMiddleware($this))
->add(new BodyParserMiddleware())
->add(new AuthenticationMiddleware($this))
->add(new TwoFactorMiddleware()); // Add TwoFactorMiddleware here
return $middlewareQueue;
}
// filepath: src/Controller/UsersController.php
namespace App\Controller;
use App\Controller\AppController;
class UsersController extends AppController
{
public function logout(): void {
$result = $this->Authentication->getResult();
// regardless of POST or GET, redirect if user is logged in
if ($result && $result->isValid()) {
// Delete Session.
$this->SimpleTwoFactor->deleteVerfifiedSession();
$this->Authentication->logout();
return $this->redirect(['controller' => 'Users', 'action' => 'login']);
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.