summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortherealssj <mehul.guptagm@gmail.com>2016-06-09 00:47:06 +0530
committertherealssj <mehul.guptagm@gmail.com>2016-06-09 00:47:06 +0530
commitc16582c1caeab1d91417c759d8e8d01cc301c59d (patch)
tree3a88d0829181106dff246d4a3f82baaff5745365 /src
parent1fe52a904a61a9b9613ab7d15089b4c9aeaba383 (diff)
downloadotp-c16582c1caeab1d91417c759d8e8d01cc301c59d.zip
otp-c16582c1caeab1d91417c759d8e8d01cc301c59d.tar.gz
otp-c16582c1caeab1d91417c759d8e8d01cc301c59d.tar.bz2
Add hotp counter window
Diffstat (limited to 'src')
-rw-r--r--src/Otp.php15
-rw-r--r--src/OtpInterface.php5
2 files changed, 16 insertions, 4 deletions
diff --git a/src/Otp.php b/src/Otp.php
index ed9b671..e5bff8f 100644
--- a/src/Otp.php
+++ b/src/Otp.php
@@ -91,9 +91,20 @@ class Otp implements OtpInterface
/* (non-PHPdoc)
* @see Otp.OtpInterface::checkHotp()
*/
- public function checkHotp($secret, $counter, $key)
+ public function checkHotp($secret, $counter, $key, $counterwindow = 5)
{
- return $this->safeCompare($this->hotp($secret, $counter), $key);
+ if(!is_numeric($counterwindow) || $counterwindow < 0){
+ throw new \InvalidArgumentException('Invalid counterwindow supplied');
+ }
+
+ for($c = 0; $c <= $counterwindow; $c = $c + 1) {
+
+ if($this->safeCompare($this->hotp($secret, $counter + $c), $key)){
+ return $counter + $c;
+ }
+ }
+
+ return false;
}
/* (non-PHPdoc)
diff --git a/src/OtpInterface.php b/src/OtpInterface.php
index 62e60c8..88241cb 100644
--- a/src/OtpInterface.php
+++ b/src/OtpInterface.php
@@ -47,10 +47,11 @@ interface OtpInterface
* @param string $secret Base32 Secret String
* @param integer $counter Counter
* @param string $key User supplied key
+ * @param integer $counterwindow Size of the look-ahead window
*
- * @return boolean True if key is correct
+ * @return int|boolean the counter if key is correct else false
*/
- function checkHotp($secret, $counter, $key);
+ function checkHotp($secret, $counter, $key, $counterwindow);
/**
* Checks Totp agains a key