From 310c18e6bbd8e7f78a0a45f0501cb1dc6fab2159 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 20 Jun 2018 18:27:34 +0300 Subject: move OTPHP to vendor/; additionally move Base32 class to OTPHP namespace --- vendor/OTPHP/TOTP.php | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 vendor/OTPHP/TOTP.php (limited to 'vendor/OTPHP/TOTP.php') diff --git a/vendor/OTPHP/TOTP.php b/vendor/OTPHP/TOTP.php new file mode 100644 index 000000000..10a1f42f3 --- /dev/null +++ b/vendor/OTPHP/TOTP.php @@ -0,0 +1,106 @@ +interval = isset($opt['interval']) ? $opt['interval'] : 30; + parent::__construct($s, $opt); + } + + /** + * Get the password for a specific timestamp value + * + * @param integer $timestamp the timestamp which is timecoded and + * used to seed the hmac hash function. + * @return integer the One Time Password + */ + public function at($timestamp) { + return $this->generateOTP($this->timecode($timestamp)); + } + + /** + * Get the password for the current timestamp value + * + * @return integer the current One Time Password + */ + public function now() { + return $this->generateOTP($this->timecode(time())); + } + + /** + * Verify if a password is valid for a specific counter value + * + * @param integer $otp the one-time password + * @param integer $timestamp the timestamp for the a given time, defaults to current time. + * @return bool true if the counter is valid, false otherwise + */ + public function verify($otp, $timestamp = null) { + if($timestamp === null) + $timestamp = time(); + return ($otp == $this->at($timestamp)); + } + + /** + * Returns the uri for a specific secret for totp method. + * Can be encoded as a image for simple configuration in + * Google Authenticator. + * + * @param string $name the name of the account / profile + * @return string the uri for the hmac secret + */ + public function provisioning_uri($name) { + return "otpauth://totp/".urlencode($name)."?secret={$this->secret}"; + } + + /** + * Transform a timestamp in a counter based on specified internal + * + * @param integer $timestamp + * @return integer the timecode + */ + protected function timecode($timestamp) { + return (int)( (((int)$timestamp * 1000) / ($this->interval * 1000))); + } + } + +} -- cgit v1.2.3-54-g00ecf