You are here

public static function Google2FA::verifyKey in Google Authenticator login 7

Verifys a key against the current timestamp.

Parameters

string $b32seed: Seed to use

string $key: User specified key

int $window: How many windows to use.

bool $use_timestamp: Use the timestamp.

Return value

bool TRUE is key is valid.

File

tests/ga_login_test/ga_login_test.module, line 187
ga_login_test module.

Class

Google2FA
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Code

public static function verifyKey($b32seed, $key, $window = 4, $use_timestamp = TRUE) {
  $timestamp = self::getTimestamp();
  if ($use_timestamp !== TRUE) {
    $timestamp = (int) $use_timestamp;
  }
  $binary_seed = self::base32Decode($b32seed);
  for ($ts = $timestamp - $window; $ts <= $timestamp + $window; $ts++) {
    if (self::oathHotp($binary_seed, $ts) == $key) {
      return TRUE;
    }
  }
  return FALSE;
}