From 58ba8480f26aa60d9b2b7ed74cc207a966f4c1b7 Mon Sep 17 00:00:00 2001 From: jmoleiro Date: Sat, 10 Oct 2020 23:02:11 -0300 Subject: [PATCH] Added Image support for FreeOPT as explained on this StackOverflow answer: https://stackoverflow.com/a/50410063 --- lib/TwoFactorAuth.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/TwoFactorAuth.php b/lib/TwoFactorAuth.php index 7bc067d..b0d4ab4 100644 --- a/lib/TwoFactorAuth.php +++ b/lib/TwoFactorAuth.php @@ -13,6 +13,7 @@ class TwoFactorAuth private $period; private $digits; private $issuer; + private $image; private $qrcodeprovider = null; private $rngprovider = null; private $timeprovider = null; @@ -179,7 +180,8 @@ public function getQRText($label, $secret) . '&issuer=' . rawurlencode($this->issuer) . '&period=' . intval($this->period) . '&algorithm=' . rawurlencode(strtoupper($this->algorithm)) - . '&digits=' . intval($this->digits); + . '&digits=' . intval($this->digits) + . ($this->image != '' ? '&image=' . rawurlencode($this->image) : ''); } private function base32Decode($value) @@ -253,4 +255,17 @@ public function getTimeProvider() } return $this->timeprovider; } + + /** + * Set the image url used by FreeOTP + */ + public function setImage($image) + { + $ext = explode(".", $image); + //Image must be PNG + if (strtolower(end($ext)) == "png") { + $this->image = $image; + } + } + } \ No newline at end of file