diff options
author | Andrew Dolgov <[email protected]> | 2018-06-20 18:27:34 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2018-06-20 18:27:34 +0300 |
commit | 310c18e6bbd8e7f78a0a45f0501cb1dc6fab2159 (patch) | |
tree | 1aee50612509895272be3d11b32b08f7e8b0e497 /vendor/OTPHP/HOTP.php | |
parent | df47100ad10117f67dd0fb86f270cdd2d24b5692 (diff) |
move OTPHP to vendor/; additionally move Base32 class to OTPHP namespace
Diffstat (limited to 'vendor/OTPHP/HOTP.php')
-rw-r--r-- | vendor/OTPHP/HOTP.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/OTPHP/HOTP.php b/vendor/OTPHP/HOTP.php new file mode 100644 index 000000000..7092fd9ff --- /dev/null +++ b/vendor/OTPHP/HOTP.php @@ -0,0 +1,74 @@ +<?php +/* + * Copyright (c) 2011 Le Lag + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +namespace OTPHP { + /** + * HOTP - One time password generator + * + * The HOTP class allow for the generation + * and verification of one-time password using + * the HOTP specified algorithm. + * + * This class is meant to be compatible with + * Google Authenticator + * + * This class was originally ported from the rotp + * ruby library available at https://github.com/mdp/rotp + */ + class HOTP extends OTP { + /** + * Get the password for a specific counter value + * @param integer $count the counter which is used to + * seed the hmac hash function. + * @return integer the One Time Password + */ + public function at($count) { + return $this->generateOTP($count); + } + + + /** + * Verify if a password is valid for a specific counter value + * + * @param integer $otp the one-time password + * @param integer $counter the counter value + * @return bool true if the counter is valid, false otherwise + */ + public function verify($otp, $counter) { + return ($otp == $this->at($counter)); + } + + /** + * Returns the uri for a specific secret for hotp method. + * Can be encoded as a image for simple configuration in + * Google Authenticator. + * + * @param string $name the name of the account / profile + * @param integer $initial_count the initial counter + * @return string the uri for the hmac secret + */ + public function provisioning_uri($name, $initial_count) { + return "otpauth://hotp/".urlencode($name)."?secret={$this->secret}&counter=$initial_count"; + } + } + +} |