google2fa = $google2fa ?? new Google2FA; } public function generateSecret(): string { return $this->google2fa->generateSecretKey(); } public function verify(string $secret, string $code): bool { $code = trim($code); if ($secret === '' || $code === '') { return false; } return (bool) $this->google2fa->verifyKey($secret, $code); } public function otpAuthUrl(string $username, string $secret, string $label = 'admin'): string { $issuer = (string) config('app.name', 'Coruna Lab'); return $this->google2fa->getQRCodeUrl($issuer, $username.'@'.$label, $secret); } public function qrSvg(string $otpAuthUrl, int $size = 200): string { $writer = new Writer(new ImageRenderer( new RendererStyle($size), new SvgImageBackEnd )); return $writer->writeString($otpAuthUrl); } }