|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* A two factor authentication module that protects both the admin and customer logins |
|
4
|
|
|
* Copyright (C) 2017 Ross Mitchell |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of Rossmitchell/Twofactor. |
|
7
|
|
|
* |
|
8
|
|
|
* Rossmitchell/Twofactor is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace Rossmitchell\Twofactor\Model\GoogleTwoFactor; |
|
23
|
|
|
|
|
24
|
|
|
use PragmaRX\Google2FA\Google2FA; |
|
25
|
|
|
|
|
26
|
|
|
class QRCode |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Google2FA |
|
30
|
|
|
*/ |
|
31
|
|
|
private $google2FA; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* QRCode constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param Google2FA $google2FA |
|
37
|
|
|
*/ |
|
38
|
12 |
|
public function __construct(Google2FA $google2FA) |
|
39
|
|
|
{ |
|
40
|
12 |
|
$this->google2FA = $google2FA; |
|
41
|
12 |
|
} |
|
42
|
|
|
|
|
43
|
5 |
|
public function generateQRCode($companyName, $email, $secret) |
|
44
|
|
|
{ |
|
45
|
5 |
|
$qrCode = $this->google2FA->getQRCodeInline($companyName, $email, $secret); |
|
46
|
|
|
|
|
47
|
5 |
|
return $qrCode; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
public function displayCurrentCode($secret) |
|
51
|
|
|
{ |
|
52
|
2 |
|
$timeStamp = $this->google2FA->getTimestamp(); |
|
53
|
2 |
|
$seed = $this->google2FA->base32Decode($secret); |
|
54
|
2 |
|
$code = $this->google2FA->oathHotp($seed, $timeStamp); |
|
55
|
|
|
|
|
56
|
2 |
|
return $code; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|