/** * @dataProvider data_testCheckTOTP */ public function testCheckTOTP($offset, $expected) { foreach ($this->hash_types as $type) { $code = $this->otp_auth->generateCode($this->secret, $this->otp_auth->getTimestampCounter(time()) + $offset, $type); $this->assertSame($expected, $this->otp_auth->checkTOTP($this->secret, $code, $type)); } }
/** * Do the actual registration of a new security key. * * @return boolean Result of the registration. * @throws http_exception */ public function register() { $secret = $this->request->variable('secret', ''); $otp = $this->request->variable('register', ''); if (!$this->otp->checkTOTP($secret, $otp, 'sha1')) { throw new http_exception(400, 'TFA_OTP_INVALID_KEY'); } $sql_ary = array('user_id' => $this->user->data['user_id'], 'secret' => $secret, 'registered' => time(), 'last_used' => time()); $sql = 'INSERT INTO ' . $this->otp_registration_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); }