summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Otp.php37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/Otp.php b/src/Otp.php
index 1df9782..6fd49e8 100644
--- a/src/Otp.php
+++ b/src/Otp.php
@@ -56,6 +56,13 @@ class Otp implements OtpInterface
* @var string
*/
protected $algorithm = 'sha1';
+
+ /**
+ * Time offset between system time and GMT in seconds
+ *
+ * @var integer
+ */
+ protected $totpOffset = 0;
/* (non-PHPdoc)
* @see Otp.OtpInterface::hotp()
@@ -252,6 +259,34 @@ class Otp implements OtpInterface
{
return $this->digits;
}
+
+ /**
+ * Set offset between system time and GMT
+ *
+ * @param integer $offset GMT - time()
+ * @throws \InvalidArgumentException
+ * @return \Otp\Otp
+ */
+ public function setTotpOffset($offset)
+ {
+ if (!is_int($offset)) {
+ throw new \InvalidArgumentException('Offset must be an integer');
+ }
+
+ $this->totpOffset = $offset;
+
+ return $this;
+ }
+
+ /**
+ * Returns offset between system time and GMT in seconds
+ *
+ * @return integer
+ */
+ public function getTotpOffset()
+ {
+ return $this->totpOffset;
+ }
/**
* Generates a binary counter for hashing
@@ -275,7 +310,7 @@ class Otp implements OtpInterface
*/
private function getTimecounter()
{
- return floor(time() / $this->period);
+ return floor((time() + $this->totpOffset) / $this->period);
}
/**