You are here

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

Extracts the OTP from the SHA1 hash.

Parameters

binary $hash: Hash to extract OTP from.

Return value

int OTP.

1 call to Google2FA::oathTruncate()
Google2FA::oathHotp in tests/ga_login_test/ga_login_test.module
Takes the secret key and the timestamp and returns the OTP.

File

tests/ga_login_test/ga_login_test.module, line 214
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 oathTruncate($hash) {
  $offset = ord($hash[19]) & 0xf;
  return ((ord($hash[$offset + 0]) & 0x7f) << 24 | (ord($hash[$offset + 1]) & 0xff) << 16 | (ord($hash[$offset + 2]) & 0xff) << 8 | ord($hash[$offset + 3]) & 0xff) % pow(10, self::OTPLENGTH);
}