<?php
namespace App\Service;
use OTPHP\TOTP;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\PngWriter;
use Symfony\Component\HttpFoundation\Response;
class TOTPService
{
private $totp;
public function __construct()
{
$this->totp = TOTP::createFromSecret('JBSWY3DPEHPK3PXP');
}
public function getSecret(): string
{
return $this->totp->getSecret();
}
public function getProvisioningUri(string $userEmail): string
{
$this->totp->setPeriod(30);
$this->totp->setLabel( 'aietftoken.com- ' .$userEmail);
return $this->totp->getProvisioningUri();
}
public function generateQRCode(string $provisioningUri)
{
$qrCode = new QrCode($provisioningUri);
$writer = new PngWriter();
// Generate QR code image
$dataUri = $writer->write($qrCode);
return $dataUri->getDataUri();
}
public function verifyOTP()
{
return $this->totp->now();
}
}
?>