Server IP : 85.214.239.14 / Your IP : 18.219.255.63 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/wordpress/phpMyAdmin/vendor/pragmarx/google2fa-qrcode/src/ |
Upload File : |
<?php namespace PragmaRX\Google2FAQRCode; use BaconQrCode\Renderer\Image\Png; use BaconQrCode\Renderer\Image\RendererInterface; use BaconQrCode\Writer as BaconQrCodeWriter; use PragmaRX\Google2FA\Google2FA as Google2FAPackage; use BaconQrCode\Renderer\ImageRenderer; use BaconQrCode\Renderer\Image\ImageBackEndInterface; use BaconQrCode\Renderer\Image\ImagickImageBackEnd; use BaconQrCode\Renderer\RendererStyle\RendererStyle; use BaconQrCode\Writer; class Google2FA extends Google2FAPackage { /** * @var ImageBackEndInterface|RendererInterface|null $imageBackEnd */ protected $imageBackEnd; /** * Google2FA constructor. * * @param ImageBackEndInterface|RendererInterface|null $imageBackEnd */ public function __construct($imageBackEnd = null) { if ($this->getBaconQRCodeVersion() === 1) { if ($imageBackEnd instanceof RendererInterface) { $this->imageBackEnd = $imageBackEnd; } else { $this->imageBackEnd = new Png(); } } else { if ($imageBackEnd instanceof ImageBackEndInterface) { $this->imageBackEnd = $imageBackEnd; } else { $this->imageBackEnd = new ImagickImageBackEnd(); } } } /** * Generates a QR code data url to display inline. * * @param string $company * @param string $holder * @param string $secret * @param int $size * @param string $encoding Default to UTF-8 * * @return string */ public function getQRCodeInline($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { return $this->getBaconQRCodeVersion() === 1 ? $this->getQRCodeInlineV1($company, $holder, $secret, $size, $encoding) : $this->getQRCodeInlineV2($company, $holder, $secret, $size, $encoding); } /** * Generates a QR code data url to display inline for Bacon QRCode v1 * * @param string $company * @param string $holder * @param string $secret * @param int $size * @param string $encoding Default to UTF-8 * * @return string */ public function getQRCodeInlineV1($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { $url = $this->getQRCodeUrl($company, $holder, $secret); $renderer = $this->imageBackEnd; $renderer->setWidth($size); $renderer->setHeight($size); $bacon = new BaconQrCodeWriter($renderer); $data = $bacon->writeString($url, $encoding); if ($this->imageBackEnd instanceof Png) { return 'data:image/png;base64,'.base64_encode($data); } return $data; } /** * Generates a QR code data url to display inline for Bacon QRCode v2 * * @param string $company * @param string $holder * @param string $secret * @param int $size * @param string $encoding Default to UTF-8 * * @return string */ public function getQRCodeInlineV2($company, $holder, $secret, $size = 200, $encoding = 'utf-8') { $renderer = new ImageRenderer( (new RendererStyle($size))->withSize($size), $this->imageBackEnd ); $bacon = new Writer($renderer); $data = $bacon->writeString( $this->getQRCodeUrl($company, $holder, $secret), $encoding ); if ($this->imageBackEnd instanceof ImagickImageBackEnd) { return 'data:image/png;base64,'.base64_encode($data); } return $data; } /** * Get Bacon QRCode current version * * @return int */ public function getBaconQRCodeVersion() { return class_exists('BaconQrCode\Renderer\Image\Png') && class_exists('BaconQrCode\Writer') ? 1 : 2; } }