1<?php
2// must be run within Dokuwiki
3if(!defined('DOKU_INC')) die();
4//Load the PHPGangsta_GoogleAuthenticator Class
5require_once(dirname(__FILE__).'/GoogleAuthenticator.php');
6/**
7 * Google Authenticator Two Factor Authentication
8 *
9 * @author Daniel Popp dan@danpopp.net
10 */
11class auth_plugin_authgoogle2fa extends auth_plugin_authplain  {
12    function __construct() {
13        parent::__construct();
14    }
15    function __destruct() {
16        //parent::__destruct();
17    }
18    function checkPass($user,$pass) {
19        $secret = $this->getConf("google_secret");
20        define('GOOGLE_AUTH_SECRET', $secret);
21        $tslack = $this->getConf("timeout_slack");
22        $enable = $this->getConf("use2fa_verify");
23        $twofactor = true;
24        if(!defined('GOOGLE_AUTH_SECRET')) $twofactor=false;
25        if($enable==0) $twofactor=false;
26        if($twofactor==true) {
27            if (isset($_POST['p'])) {
28                $ga = new PHPGangsta_GoogleAuthenticator();
29                $twofa = $_POST['t'];
30                $checkResult = $ga->verifyCode($secret, $twofa, $tslack);
31            }
32            else {
33                $checkResult = false;
34            }
35            if ($checkResult != true) {
36                return false;
37            }
38        }
39        return parent::checkPass($user,$pass);
40    }
41}
42?>
43