PHP code example of xruff / totpauth
1. Go to this page and download the library: Download xruff/totpauth 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/ */
xruff / totpauth example snippets
use XRuff\TotpAuth\Auth;
use Nette\Application\UI;
class HomepagePresenter extends Nette\Application\UI\Presenter
{
/** @var Auth $auth */
public $auth;
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
public function renderDefault() {
$this->template->qrCode = $this->auth->getQrBase64();
}
public function handleSaveUrl()
{
$this->auth->saveSecret();
$this->redirect('this');
}
public function handleResetUrl()
{
$this->auth->resetSecret();
$this->redirect('this');
}
protected function createComponentCodeForm()
{
$form = new UI\Form;
$form->addText('code', 'Code');
$form->addSubmit('submit', 'Auth me');
$form->onSuccess[] = [$this, 'codeFormSucceeded'];
return $form;
}
public function codeFormSucceeded(UI\Form $form, $values)
{
if ($this->auth->verify($values->code)) {
$this->flashMessage('Success!');
} else {
$this->flashMessage('Wrong code.');
}
$this->redirect('this');
}
}