snappymail/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/TwoFactorAuth.php
djmaze 2cada68f41 Privacy/GDPR friendly version (removed: Social, Gravatar, Facebook, Google, Twitter, DropBox, OwnCloud)
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
2020-03-09 17:04:17 +01:00

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