PHP code example of holabs / totp

1. Go to this page and download the library: Download holabs/totp 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/ */

    

holabs / totp example snippets


 

use Holabs\TOTP;
use Nette\Application\UI\Form;
use Nette\Utils\ArrayHash;

/**
 * @author       Tomáš Holan <[email protected]>
 * @package      holabs/totp
 * @copyright    Copyright © 2016, Tomáš Holan [www.tomasholan.cz]
 */
class SignPresenter extends BasePresenter
{

	/** @var TOTP @inject */
	public $totp;


	public function actionDefault() {
		if (!isset($_SESSION['totp'])) {
			// Store in Database or file is better
			// Every time you generate secret, your use have to delete old and add new in APP
			$_SESSION['totp'] = $this->totp->generateSecret();
		}

		$secret = $_SESSION['totp'];

		$this->template->qr = $this->totp->getQRUrl($secret);
		$this->template->secret = chunk_split($secret, 4, ' ');
		$this->template->status = '';
	}


	/**
	 * Sign-up form factory.
	 * @return Form
	 */
	protected function createComponentSecondFactor()
	{
		$form = new Form();

		$form->addText('code', 'Code', 6)
			->setRequired('Code is