src/Service/TOTPService.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use OTPHP\TOTP;
  4. use Endroid\QrCode\QrCode;
  5. use Endroid\QrCode\Writer\PngWriter;
  6. use Symfony\Component\HttpFoundation\Response;
  7. class TOTPService
  8. {
  9.     private $totp;
  10.     public function __construct()
  11.     {
  12.         $this->totp TOTP::createFromSecret('JBSWY3DPEHPK3PXP'); 
  13.    
  14.       
  15.     }
  16.     public function getSecret(): string
  17.     {
  18.         return $this->totp->getSecret();
  19.     }
  20.     public function getProvisioningUri(string $userEmail): string
  21.     
  22.         $this->totp->setPeriod(30); 
  23.         $this->totp->setLabel'aietftoken.com- ' .$userEmail);
  24.         return $this->totp->getProvisioningUri();
  25.     }
  26.     public function generateQRCode(string $provisioningUri)
  27.     {
  28.         $qrCode = new QrCode($provisioningUri);
  29.         $writer = new PngWriter();
  30.         
  31.         // Generate QR code image
  32.         $dataUri $writer->write($qrCode);
  33.         return $dataUri->getDataUri();
  34.     }
  35.     public function verifyOTP()
  36.     {
  37.         return $this->totp->now();
  38.     }
  39. }
  40. ?>