function GoogleAuthenticator::oath_hotp in Google Authenticator login 6
3 calls to GoogleAuthenticator::oath_hotp()
File
- ./
ga4php.php, line 379
Class
Code
function oath_hotp($key, $counter) {
$key = pack("H*", $key);
$cur_counter = array(
0,
0,
0,
0,
0,
0,
0,
0,
);
for ($i = 7; $i >= 0; $i--) {
$cur_counter[$i] = pack('C*', $counter);
$counter = $counter >> 8;
}
$bin_counter = implode($cur_counter);
// Pad to 8 chars
if (strlen($bin_counter) < 8) {
$bin_counter = str_repeat(chr(0), 8 - strlen($bin_counter)) . $bin_counter;
}
// HMAC
$hash = hash_hmac('sha1', $bin_counter, $key);
return str_pad($this
->oath_truncate($hash), 6, "0", STR_PAD_LEFT);
}