mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-26 18:49:20 +03:00
Also removed: POP3, OAuth2 and update feature Added: admin password_hash/password_verify Requires: PHP 7.3+ Replaced: CRLF with LF Replaced: pclZip with ZipArchive
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace RainLoop\Providers;
|
|
|
|
class TwoFactorAuth extends \RainLoop\Providers\AbstractProvider
|
|
{
|
|
/**
|
|
* @var \RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface
|
|
*/
|
|
private $oDriver;
|
|
|
|
public function __construct(?\RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface $oDriver = null)
|
|
{
|
|
$this->oDriver = $oDriver;
|
|
}
|
|
|
|
public function IsActive() : bool
|
|
{
|
|
return $this->oDriver instanceof \RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface;
|
|
}
|
|
|
|
public function GetQRCodeGoogleUrl(string $sName, string $sSecret, string $sTitle = '') : string
|
|
{
|
|
$sUrl = sprintf('otpauth://%s/%s?secret=%s&issuer=%s', 'totp', urlencode($sName), $sSecret, urlencode($sTitle));
|
|
return 'https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl='.\urlencode($sUrl);
|
|
}
|
|
|
|
public function CreateSecret() : string
|
|
{
|
|
$sResult = '';
|
|
if ($this->IsActive())
|
|
{
|
|
$sResult = $this->oDriver->CreateSecret();
|
|
}
|
|
|
|
return $sResult;
|
|
}
|
|
|
|
public function VerifyCode(string $sSecret, string $sCode) : bool
|
|
{
|
|
$bResult = false;
|
|
if ($this->IsActive())
|
|
{
|
|
$bResult = $this->oDriver->VerifyCode($sSecret, $sCode);
|
|
}
|
|
|
|
return $bResult;
|
|
}
|
|
}
|