/**
  * Get an otp instance
  * @param string $label A custom label to use
  * @param null $issuer A custom issuer to use
  * @return OTPHP\TOTP
  */
 public function getInstance($label = 'faheem00', $issuer = null)
 {
     $this->totp = new TOTP($label, $this->createSecret());
     if ($issuer) {
         $this->totp->setIssuer($issuer);
     }
     return $this->totp;
 }
 /**
  * @dataProvider testProvisioningURIData
  */
 public function testProvisioningURI($secret, $label, $issuer, $expectedResult)
 {
     $totp = new TOTP($secret);
     $totp->setLabel($label);
     $totp->setIssuer($issuer);
     $this->assertEquals($expectedResult, $totp->getProvisioningUri());
 }
 public function renderQrCodeAction()
 {
     /** @var AccountInterface $account */
     $account = $this->zourceAccount();
     $oneTimePassword = new TOTP($account->getContact()->getFullName(), $this->tfaService->getSecret());
     $oneTimePassword->setIssuer('Zource');
     $oneTimePassword->setIssuerIncludedAsParameter(true);
     $oneTimePassword->setParameter('image', $this->url()->fromRoute('settings/security/tfa-image', [], ['force_canonical' => true]));
     $filePath = tempnam('data/tmp/', '2fa-qr-');
     $renderer = new Png();
     $renderer->setHeight(256);
     $renderer->setWidth(256);
     $writer = new Writer($renderer);
     $writer->writeFile($oneTimePassword->getProvisioningUri(true), $filePath);
     $response = new Stream();
     $response->setCleanup(true);
     $response->setStream(fopen($filePath, 'rb'));
     $response->setStreamName($filePath);
     $headers = $response->getHeaders();
     $headers->addHeaderLine('Content-Length', filesize($filePath));
     $headers->addHeaderLine('Content-Type', 'image/png');
     return $response;
 }