2017 © Pedro Peláez
 

library totpauth

Nette extension for Time-Based One-Time Password Algorithm

image

xruff/totpauth

Nette extension for Time-Based One-Time Password Algorithm

  • Wednesday, February 28, 2018
  • by xruff
  • Repository
  • 2 Watchers
  • 0 Stars
  • 58 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 29 % Grown

The README.md

TotpAuth

Nette extension for Time-Based One-Time Password Algorithm, (*1)

Requirements

Package requires PHP 7.0 or higher, (*2)

Installation

The best way to install XRuff/TotpAuth is using Composer:, (*3)

$ composer require xruff/totpAuth

Scenario

  • logged user activate 2FA in account settings:
  • next login to your application:
    • user log in standard way (login + password...) and see second login page with form with one field
    • provide code from Authenticator mobile aplication
    • pass through if provided code is right

Documentation

Assumptions:, (*4)

  • create table qr in database, use schema from file sql/qr.sql
  • $user->indentity have to contain properties id and username

Configuration in config.neon., (*5)

extensions:
    totpAuth: XRuff\TotpAuth\DI\TotpAuthExtension

totpAuth:
    issuer: NameOfMyApp  # mandatory
    identityKey: login   # optional, Default is 'login' eg $user->identity->login
    timeWindow: 1        # optional - time tolerance
    codeSize: '300x300'  # optional - size ofgenerated QR code

Presenter:, (*6)


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'); } }

default.latte:, (*7)

    ...
    {if $qrCode}
        <img src="{$qrCode|nocheck}" alt="">
        <br>
        <a n:href="saveUrl!" class="btn btn-success">Confirm Code (have been added to Mobile Authenticator App)</a>
    {else}
        {control codeForm}
        <a n:href="resetUrl!" class="btn btn-success">Reset auth code</a>
    {/if}
    ...

Repository https://github.com/XRuff/TotpAuth., (*8)

The Versions

28/02 2018

dev-master

9999999-dev

Nette extension for Time-Based One-Time Password Algorithm

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Lauko

component google qrcode qr nette totp nette-framework

31/08 2017

v1.0.0

1.0.0.0

Nette extension for Time-Based One-Time Password Algorithm

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pavel Lauko

component google qrcode qr nette totp nette-framework