diff options
author | Antonio Carlos Ribeiro <acr@antoniocarlosribeiro.com> | 2017-07-06 14:44:49 -0300 |
---|---|---|
committer | Antonio Carlos Ribeiro <acr@antoniocarlosribeiro.com> | 2017-07-06 14:44:49 -0300 |
commit | e56614ad693ac4fb406ac0317ed7fb6dc996caf8 (patch) | |
tree | e4080d3db91c3929ef659623dfcfb9cc1c14f4c7 | |
parent | 3d7e16f95f08adaf344996b3dba8f3aa941d1f72 (diff) | |
download | google2fa-e56614ad693ac4fb406ac0317ed7fb6dc996caf8.zip google2fa-e56614ad693ac4fb406ac0317ed7fb6dc996caf8.tar.gz google2fa-e56614ad693ac4fb406ac0317ed7fb6dc996caf8.tar.bz2 |
Refactor method
-rw-r--r-- | src/Google2FA.php | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/Google2FA.php b/src/Google2FA.php index c30330c..25ea4dc 100644 --- a/src/Google2FA.php +++ b/src/Google2FA.php @@ -184,6 +184,21 @@ class Google2FA } /** + * Make a window based starting timestamp. + * + * @param $window + * @param $timestamp + * @param $oldTimestamp + * @return mixed + */ + private function makeStartingTimestamp($window, $timestamp, $oldTimestamp) + { + return $oldTimestamp === Constants::ARGUMENT_NOT_SET + ? $timestamp - $this->getWindow($window) + : max($timestamp - $this->getWindow($window), $oldTimestamp + 1); + } + + /** * Get/use a starting timestamp for key verification. * * @param string|int|null $timestamp @@ -345,15 +360,11 @@ class Google2FA { $timestamp = $this->makeTimestamp($timestamp); - $startingTimestamp = $oldTimestamp === Constants::ARGUMENT_NOT_SET - ? $timestamp - $this->getWindow($window) - : max($timestamp - $this->getWindow($window), $oldTimestamp + 1); - return $this->findValidOTP( $this->base32Decode($this->getSecret($secret)), $key, $window, - $startingTimestamp, + $this->makeStartingTimestamp($window, $timestamp, $oldTimestamp), $timestamp, $oldTimestamp ); |