mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-18 02:33:05 +00:00
Merge remote-tracking branch 'igorsantos/qr-logos'
This commit is contained in:
@@ -25,6 +25,11 @@ class EndroidQrCodeProvider implements IQRCodeProvider
|
||||
}
|
||||
|
||||
public function getQRCodeImage($qrtext, $size)
|
||||
{
|
||||
return $this->qrCodeInstance($qrtext, $size)->writeString();
|
||||
}
|
||||
|
||||
protected function qrCodeInstance($qrtext, $size)
|
||||
{
|
||||
$qrCode = new QrCode($qrtext);
|
||||
$qrCode->setSize($size);
|
||||
@@ -34,7 +39,7 @@ class EndroidQrCodeProvider implements IQRCodeProvider
|
||||
$qrCode->setBackgroundColor($this->bgcolor);
|
||||
$qrCode->setForegroundColor($this->color);
|
||||
|
||||
return $qrCode->writeString();
|
||||
return $qrCode;
|
||||
}
|
||||
|
||||
private function handleColor($color)
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace RobThree\Auth\Providers\Qr;
|
||||
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
use Endroid\QrCode\QrCode;
|
||||
|
||||
class EndroidQrCodeWithLogoProvider extends EndroidQrCodeProvider
|
||||
{
|
||||
protected $logoPath;
|
||||
protected $logoSize;
|
||||
|
||||
/**
|
||||
* Adds an image to the middle of the QR Code.
|
||||
* @param string $path Path to an image file
|
||||
* @param array|int $size Just the width, or [width, height]
|
||||
*/
|
||||
public function setLogo($path, $size = null)
|
||||
{
|
||||
$this->logoPath = $path;
|
||||
$this->logoSize = (array)$size;
|
||||
}
|
||||
|
||||
protected function qrCodeInstance($qrtext, $size) {
|
||||
$qrCode = parent::qrCodeInstance($qrtext, $size);
|
||||
|
||||
if ($this->logoPath) {
|
||||
$qrCode->setLogoPath($this->logoPath);
|
||||
if ($this->logoSize) {
|
||||
$qrCode->setLogoSize($this->logoSize[0], $this->logoSize[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return $qrCode;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ class TwoFactorAuth
|
||||
*/
|
||||
public function verifyCode($secret, $code, $discrepancy = 1, $time = null, &$timeslice = 0)
|
||||
{
|
||||
$timetamp = $this->getTime($time);
|
||||
$timestamp = $this->getTime($time);
|
||||
|
||||
$timeslice = 0;
|
||||
|
||||
@@ -152,7 +152,7 @@ class TwoFactorAuth
|
||||
// of the match. Each iteration we either set the timeslice variable to the timeslice of the match
|
||||
// or set the value to itself. This is an effort to maintain constant execution time for the code.
|
||||
for ($i = -$discrepancy; $i <= $discrepancy; $i++) {
|
||||
$ts = $timetamp + ($i * $this->period);
|
||||
$ts = $timestamp + ($i * $this->period);
|
||||
$slice = $this->getTimeSlice($ts);
|
||||
$timeslice = $this->codeEquals($this->getCode($secret, $ts), $code) ? $slice : $timeslice;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user