[
  {
    "path": ".gitignore",
    "content": ".bak\n"
  },
  {
    "path": "LICENCE",
    "content": "Copyright (c) 2011 Le Lag \n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n"
  },
  {
    "path": "README.markdown",
    "content": "# OTPHP - A PHP One Time Password Library\n\nA php library for generating one time passwords according to [ RFC 4226 ](http://tools.ietf.org/html/rfc4226) and the [ HOTP RFC ](http://tools.ietf.org/html/draft-mraihi-totp-timebased-00)\n\nThis is compatible with Google Authenticator apps available for Android and iPhone, and now in use on GMail\n\nThis is a port of the rotp ruby library available at https://github.com/mdp/rotp\n\nNote : This project has not been updated since it was created. If you need a PHP OTP library, you should check out the great fork by Spomky-Labs at https://github.com/Spomky-Labs/otphp which has been improved and is currently maintained.\n\n\n## Quick overview of using One Time Passwords on your phone\n\n* OTP's involve a shared secret, stored both on the phone and the server\n* OTP's can be generated on a phone without internet connectivity(AT&T mode)\n* OTP's should always be used as a second factor of authentication(if your phone is lost, you account is still secured with a password)\n* Google Authenticator allows you to store multiple OTP secrets and provision those using a QR Code(no more typing in the secret)\n\n## Installation\n\n   clone this repository and include lib/otphp.php in your project. \n\n## Use\n\n### Time based OTP's\n\n    $totp = new \\OTPHP\\TOTP(\"base32secret3232\");\n    $totp->now(); // => 492039\n\n    // OTP verified for current time\n    $totp->verify(492039); // => true\n    //30s later\n    $totp->verify(492039); // => false\n\n### Counter based OTP's\n\n    $hotp = new \\OTPHP\\HOTP(\"base32secretkey3232\");\n    $hotp->at(0); // => 260182\n    $hotp->at(1); // => 55283\n    $hotp->at(1401); // => 316439\n\n    // OTP verified with a counter\n    $totp->verify(316439, 1401); // => true\n    $totp->verify(316439, 1402); // => false\n\n### Google Authenticator Compatible\n\nThe library works with the Google Authenticator iPhone and Android app, and also\nincludes the ability to generate provisioning URI's for use with the QR Code scanner\nbuilt into the app.\n\n    $totp->provisioning_uri(); // => 'otpauth://totp/alice@google.com?secret=JBSWY3DPEHPK3PXP'\n    $hotp->provisioning_uri(); // => 'otpauth://hotp/alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=0'\n\nThis can then be rendered as a QR Code which can then be scanned and added to the users\nlist of OTP credentials.\n\n#### Working example\n\nScan the following barcode with your phone, using Google Authenticator\n\n![QR Code for OTP](http://chart.apis.google.com/chart?cht=qr&chs=250x250&chl=otpauth%3A%2F%2Ftotp%2Falice%40google.com%3Fsecret%3DJBSWY3DPEHPK3PXP)\n\nNow run the following and compare the output\n\n    <?php\n    require_once('otphp/lib/otphp.php');\n    $totp = new \\OTPHP\\TOTP(\"JBSWY3DPEHPK3PXP\");\n    echo \"Current OTP: \". $totp->now();\n\n## Licence\n\nThis software is release under MIT licence.\n"
  },
  {
    "path": "lib/hotp.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nnamespace OTPHP {\n  /**\n   * HOTP - One time password generator \n   * \n   * The HOTP class allow for the generation \n   * and verification of one-time password using \n   * the HOTP specified algorithm.\n   *\n   * This class is meant to be compatible with \n   * Google Authenticator\n   *\n   * This class was originally ported from the rotp\n   * ruby library available at https://github.com/mdp/rotp\n   */\n  class HOTP extends OTP {\n    /**\n     *  Get the password for a specific counter value\n     *  @param integer $count the counter which is used to\n     *  seed the hmac hash function.\n     *  @return integer the One Time Password\n     */\n    public function at($count) {\n      return $this->generateOTP($count);\n    }\n\n\n    /**\n     * Verify if a password is valid for a specific counter value\n     *\n     * @param integer $otp the one-time password \n     * @param integer $counter the counter value\n     * @return  bool true if the counter is valid, false otherwise\n     */\n    public function verify($otp, $counter) {\n      return ($otp == $this->at($counter));\n    }\n\n    /**\n     * Returns the uri for a specific secret for hotp method.\n     * Can be encoded as a image for simple configuration in \n     * Google Authenticator.\n     *\n     * @param string $name the name of the account / profile\n     * @param integer $initial_count the initial counter \n     * @return string the uri for the hmac secret\n     */\n    public function provisioning_uri($name, $initial_count) {\n      return \"otpauth://hotp/\".urlencode($name).\"?secret={$this->secret}&counter=$initial_count\";\n    }\n  }\n\n}\n"
  },
  {
    "path": "lib/otp.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nnamespace OTPHP {\n/**\n * One Time Password Generator \n * \n * The OTP class allow the generation of one-time\n * password that is described in rfc 4xxx.\n * \n * This is class is meant to be compatible with \n * Google Authenticator.\n *\n * This class was originally ported from the rotp\n * ruby library available at https://github.com/mdp/rotp\n */\nclass OTP {\n    /**\n     * The base32 encoded secret key\n     * @var string\n     */\n    public $secret;\n\n    /**\n     * The algorithm used for the hmac hash function\n     * @var string\n     */\n    public $digest;\n\n    /**\n     * The number of digits in the one-time password\n     * @var integer\n     */ \n    public $digits;\n\n    /**\n     * Constructor for the OTP class\n     * @param string $secret the secret key\n     * @param array $opt options array can contain the\n     * following keys :\n     *   @param integer digits : the number of digits in the one time password\n     *   Currently Google Authenticator only support 6. Defaults to 6.\n     *   @param string digest : the algorithm used for the hmac hash function\n     *   Google Authenticator only support sha1. Defaults to sha1\n     *\n     * @return new OTP class.\n     */\n    public function __construct($secret, $opt = Array()) {\n      $this->digits = isset($opt['digits']) ? $opt['digits'] : 6;\n      $this->digest = isset($opt['digest']) ? $opt['digest'] : 'sha1';\n      $this->secret = $secret;\n    }\n\n    /**\n     * Generate a one-time password\n     *\n     * @param integer $input : number used to seed the hmac hash function.\n     * This number is usually a counter (HOTP) or calculated based on the current\n     * timestamp (see TOTP class).\n     * @return integer the one-time password \n     */\n    public function generateOTP($input) {\n      $hash = hash_hmac($this->digest, $this->intToBytestring($input), $this->byteSecret());\n      foreach(str_split($hash, 2) as $hex) { // stupid PHP has bin2hex but no hex2bin WTF\n        $hmac[] = hexdec($hex);\n      }\n      $offset = $hmac[19] & 0xf;\n      $code = ($hmac[$offset+0] & 0x7F) << 24 |\n        ($hmac[$offset + 1] & 0xFF) << 16 |\n        ($hmac[$offset + 2] & 0xFF) << 8 |\n        ($hmac[$offset + 3] & 0xFF);\n      return $code % pow(10, $this->digits);\n    }\n\n    /**\n     * Returns the binary value of the base32 encoded secret\n     * @access private\n     * This method should be private but was left public for\n     * phpunit tests to work.\n     * @return binary secret key\n     */\n    public function byteSecret() {\n      return \\Base32::decode($this->secret);\n    }\n\n    /**\n     * Turns an integer in a OATH bytestring\n     * @param integer $int\n     * @access private\n     * @return string bytestring\n     */\n    public function intToBytestring($int) {\n      $result = Array();\n      while($int != 0) {\n        $result[] = chr($int & 0xFF);\n        $int >>= 8;\n      }\n      return str_pad(join(array_reverse($result)), 8, \"\\000\", STR_PAD_LEFT);\n    }\n  }\n}\n"
  },
  {
    "path": "lib/otphp.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nrequire_once dirname(__FILE__).'/../vendor/libs.php';\nrequire_once dirname(__FILE__).'/otp.php';\nrequire_once dirname(__FILE__).'/hotp.php';\nrequire_once dirname(__FILE__).'/totp.php';\n\n"
  },
  {
    "path": "lib/totp.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nnamespace OTPHP {\n  /**\n   * TOTP - One time password generator \n   * \n   * The TOTP class allow for the generation \n   * and verification of one-time password using \n   * the TOTP specified algorithm.\n   *\n   * This class is meant to be compatible with \n   * Google Authenticator\n   *\n   * This class was originally ported from the rotp\n   * ruby library available at https://github.com/mdp/rotp\n   */\n  class TOTP extends OTP {\n    /**\n     * The interval in seconds for a one-time password timeframe\n     * Defaults to 30\n     * @var integer\n     */\n    public $interval;\n\n    public function __construct($s, $opt = Array()) {\n      $this->interval = isset($opt['interval']) ? $opt['interval'] : 30;\n      parent::__construct($s, $opt);\n    }\n\n    /**\n     *  Get the password for a specific timestamp value \n     *\n     *  @param integer $timestamp the timestamp which is timecoded and \n     *  used to seed the hmac hash function.\n     *  @return integer the One Time Password\n     */\n    public function at($timestamp) {\n      return $this->generateOTP($this->timecode($timestamp));\n    }\n\n    /**\n     *  Get the password for the current timestamp value \n     *\n     *  @return integer the current One Time Password\n     */\n    public function now() {\n      return $this->generateOTP($this->timecode(time()));\n    }\n\n    /**\n     * Verify if a password is valid for a specific counter value\n     *\n     * @param integer $otp the one-time password \n     * @param integer $timestamp the timestamp for the a given time, defaults to current time.\n     * @return  bool true if the counter is valid, false otherwise\n     */\n    public function verify($otp, $timestamp = null) {\n      if($timestamp === null)\n        $timestamp = time();\n      return ($otp == $this->at($timestamp));\n    }\n\n    /**\n     * Returns the uri for a specific secret for totp method.\n     * Can be encoded as a image for simple configuration in \n     * Google Authenticator.\n     *\n     * @param string $name the name of the account / profile\n     * @return string the uri for the hmac secret\n     */\n    public function provisioning_uri($name) {\n      return \"otpauth://totp/\".urlencode($name).\"?secret={$this->secret}\";\n    }\n\n    /**\n     * Transform a timestamp in a counter based on specified internal\n     *\n     * @param integer $timestamp\n     * @return integer the timecode\n     */\n    protected function timecode($timestamp) {\n      return (int)( (((int)$timestamp * 1000) / ($this->interval * 1000)));\n    }\n  }\n\n}\n"
  },
  {
    "path": "tests/HOTPTest.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nrequire_once dirname(__FILE__).'/../lib/otphp.php';\n\nclass HOPTTest extends PHPUnit_Framework_TestCase {\n  public function test_it_gets_the_good_code() {\n    $o = new \\OTPHP\\HOTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertEquals(855783,$o->at(0));\n    $this->assertEquals(549607,$o->at(500));\n    $this->assertEquals(654666,$o->at(1500));\n  }\n\n  public function test_it_verify_the_code() {\n    $o = new \\OTPHP\\HOTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertTrue($o->verify(855783, 0));\n    $this->assertTrue($o->verify(549607, 500));\n    $this->assertTrue($o->verify(654666, 1500));\n  }\n\n  public function test_it_returns_the_provisioning_uri() {\n    $o = new \\OTPHP\\HOTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertEquals(\"otpauth://hotp/name?secret=JDDK4U6G3BJLEZ7Y&counter=0\",\n      $o->provisioning_uri('name', 0));\n  }\n}\n"
  },
  {
    "path": "tests/OTPTest.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nrequire_once dirname(__FILE__).'/../lib/otphp.php';\n\nclass TestOTP extends PHPUnit_Framework_TestCase {\n\n  public function test_it_decodes_the_secret() {\n    $o = new \\OTPHP\\OTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertEquals(\"H\\306\\256S\\306\\330R\\262g\\370\", $o->byteSecret());\n  }\n\n  public function test_it_turns_an_int_into_bytestring() {\n    $o = new \\OTPHP\\OTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertEquals(\"\\000\\000\\000\\000\\000\\000\\000\\000\", $o->intToBytestring(0));\n    $this->assertEquals(\"\\000\\000\\000\\000\\000\\000\\000\\001\", $o->intToBytestring(1));\n    $this->assertEquals(\"\\000\\000\\000\\000\\000\\000\\001\\364\", $o->intToBytestring(500));\n    $this->assertEquals(\"\\000\\000\\000\\000\\000\\000\\005\\334\", $o->intToBytestring(1500));\n  }\n\n  public function test_it_generate_otp() {\n    $o = new \\OTPHP\\OTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertEquals(855783, $o->generateOTP(0));\n    $this->assertEquals(549607, $o->generateOTP(500));\n    $this->assertEquals(654666, $o->generateOTP(1500));\n  }\n}\n"
  },
  {
    "path": "tests/TOTPTest.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nrequire_once dirname(__FILE__).'/../lib/otphp.php';\n\nclass TOPTTest extends PHPUnit_Framework_TestCase {\n\n  public function test_it_has_an_interval() {\n    $o = new \\OTPHP\\TOTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertEquals(30,$o->interval);\n    $b = new \\OTPHP\\TOTP('JDDK4U6G3BJLEZ7Y', Array('interval'=>60));\n    $this->assertEquals(60,$b->interval);\n  }\n\n  public function test_it_gets_the_good_code_at_given_times() {\n    $o = new \\OTPHP\\TOTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertEquals(855783,$o->at(0));\n    $this->assertEquals(762124,$o->at(319690800));\n    $this->assertEquals(139664,$o->at(1301012137));\n  }\n\n  public function test_it_verify_the_code() {\n    $o = new \\OTPHP\\TOTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertTrue($o->verify(855783, 0));\n    $this->assertTrue($o->verify(762124, 319690800));\n    $this->assertTrue($o->verify(139664, 1301012137));\n  }\n\n  public function test_it_returns_the_provisioning_uri() {\n    $o = new \\OTPHP\\TOTP('JDDK4U6G3BJLEZ7Y');\n    $this->assertEquals(\"otpauth://totp/name?secret=JDDK4U6G3BJLEZ7Y\",\n      $o->provisioning_uri('name'));\n  }\n}\n"
  },
  {
    "path": "tests/TestTest.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\nrequire_once dirname(__FILE__).'/../lib/otphp.php';\n\nclass TestTest extends PHPUnit_Framework_TestCase {\n  public function testThatPHPUnitWorks() {\n    $this->assertEquals(1,1);\n  }\n}\n"
  },
  {
    "path": "vendor/base32.php",
    "content": "<?php\n\n/**\n * Encode in Base32 based on RFC 4648.\n * Requires 20% more space than base64  \n * Great for case-insensitive filesystems like Windows and URL's  (except for = char which can be excluded using the pad option for urls)\n *\n * @package default\n * @author Bryan Ruiz\n **/\nclass Base32 {\n\n   private static $map = array(\n        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', //  7\n        'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 15\n        'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 23\n        'Y', 'Z', '2', '3', '4', '5', '6', '7', // 31\n        '='  // padding char\n    );\n    \n   private static $flippedMap = array(\n        'A'=>'0', 'B'=>'1', 'C'=>'2', 'D'=>'3', 'E'=>'4', 'F'=>'5', 'G'=>'6', 'H'=>'7',\n        'I'=>'8', 'J'=>'9', 'K'=>'10', 'L'=>'11', 'M'=>'12', 'N'=>'13', 'O'=>'14', 'P'=>'15',\n        'Q'=>'16', 'R'=>'17', 'S'=>'18', 'T'=>'19', 'U'=>'20', 'V'=>'21', 'W'=>'22', 'X'=>'23',\n        'Y'=>'24', 'Z'=>'25', '2'=>'26', '3'=>'27', '4'=>'28', '5'=>'29', '6'=>'30', '7'=>'31'\n    );\n    \n    /**\n     *    Use padding false when encoding for urls\n     *\n     * @return base32 encoded string\n     * @author Bryan Ruiz\n     **/\n    public static function encode($input, $padding = true) {\n        if(empty($input)) return \"\";\n        $input = str_split($input);\n        $binaryString = \"\";\n        for($i = 0; $i < count($input); $i++) {\n            $binaryString .= str_pad(base_convert(ord($input[$i]), 10, 2), 8, '0', STR_PAD_LEFT);\n        }\n        $fiveBitBinaryArray = str_split($binaryString, 5);\n        $base32 = \"\";\n        $i=0;\n        while($i < count($fiveBitBinaryArray)) {    \n            $base32 .= self::$map[base_convert(str_pad($fiveBitBinaryArray[$i], 5,'0'), 2, 10)];\n            $i++;\n        }\n        if($padding && ($x = strlen($binaryString) % 40) != 0) {\n            if($x == 8) $base32 .= str_repeat(self::$map[32], 6);\n            else if($x == 16) $base32 .= str_repeat(self::$map[32], 4);\n            else if($x == 24) $base32 .= str_repeat(self::$map[32], 3);\n            else if($x == 32) $base32 .= self::$map[32];\n        }\n        return $base32;\n    }\n    \n    public static function decode($input) {\n        if(empty($input)) return;\n        $paddingCharCount = substr_count($input, self::$map[32]);\n        $allowedValues = array(6,4,3,1,0);\n        if(!in_array($paddingCharCount, $allowedValues)) return false;\n        for($i=0; $i<4; $i++){ \n            if($paddingCharCount == $allowedValues[$i] && \n                substr($input, -($allowedValues[$i])) != str_repeat(self::$map[32], $allowedValues[$i])) return false;\n        }\n        $input = str_replace('=','', $input);\n        $input = str_split($input);\n        $binaryString = \"\";\n        for($i=0; $i < count($input); $i = $i+8) {\n            $x = \"\";\n            if(!in_array($input[$i], self::$map)) return false;\n            for($j=0; $j < 8; $j++) {\n                $x .= str_pad(base_convert(@self::$flippedMap[@$input[$i + $j]], 10, 2), 5, '0', STR_PAD_LEFT);\n            }\n            $eightBits = str_split($x, 8);\n            for($z = 0; $z < count($eightBits); $z++) {\n                $binaryString .= ( ($y = chr(base_convert($eightBits[$z], 2, 10))) || ord($y) == 48 ) ? $y:\"\";\n            }\n        }\n        return $binaryString;\n    }\n}\n\n"
  },
  {
    "path": "vendor/libs.php",
    "content": "<?php\n/*\n * Copyright (c) 2011 Le Lag \n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n\n// Add any needed third party library to this directory\n\n//require_once dirname(__FILE__).'/some_lib/lib.php';\nrequire_once dirname(__FILE__).'/base32.php';\n"
  }
]