]> git.wh0rd.org - tt-rss.git/blame - lib/otphp/lib/hotp.php
remove SWF enclosure audio player
[tt-rss.git] / lib / otphp / lib / hotp.php
CommitLineData
fb70f26e
AD
1<?php
2/*
3 * Copyright (c) 2011 Le Lag
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23namespace OTPHP {
24 /**
25 * HOTP - One time password generator
26 *
27 * The HOTP class allow for the generation
28 * and verification of one-time password using
29 * the HOTP specified algorithm.
30 *
31 * This class is meant to be compatible with
32 * Google Authenticator
33 *
34 * This class was originally ported from the rotp
35 * ruby library available at https://github.com/mdp/rotp
36 */
37 class HOTP extends OTP {
38 /**
39 * Get the password for a specific counter value
40 * @param integer $count the counter which is used to
41 * seed the hmac hash function.
42 * @return integer the One Time Password
43 */
44 public function at($count) {
45 return $this->generateOTP($count);
46 }
47
48
49 /**
50 * Verify if a password is valid for a specific counter value
51 *
52 * @param integer $otp the one-time password
53 * @param integer $counter the counter value
54 * @return bool true if the counter is valid, false otherwise
55 */
56 public function verify($otp, $counter) {
57 return ($otp == $this->at($counter));
58 }
59
60 /**
61 * Returns the uri for a specific secret for hotp method.
62 * Can be encoded as a image for simple configuration in
63 * Google Authenticator.
64 *
65 * @param string $name the name of the account / profile
66 * @param integer $initial_count the initial counter
67 * @return string the uri for the hmac secret
68 */
69 public function provisioning_uri($name, $initial_count) {
70 return "otpauth://hotp/".urlencode($name)."?secret={$this->secret}&counter=$initial_count";
71 }
72 }
73
74}