From 3f21cbba86e4a8ed209ade3e345f6a92a5e579d8 Mon Sep 17 00:00:00 2001 From: foo Date: Wed, 8 May 2013 20:42:22 +0100 Subject: [PATCH] verify() on time allows one window either side --- lib/totp.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/totp.php b/lib/totp.php index 10a1f42..26a8814 100644 --- a/lib/totp.php +++ b/lib/totp.php @@ -77,7 +77,13 @@ public function now() { public function verify($otp, $timestamp = null) { if($timestamp === null) $timestamp = time(); - return ($otp == $this->at($timestamp)); + + $window = 30; + foreach (array(0, $window, -$window) as $t) + if($otp == $this->at($timestamp + $t)) + return true; + + return false; } /**