function GoogleAuthenticator::oath_hotp in Google Authenticator login 6
3 calls to GoogleAuthenticator::oath_hotp()
- ga_loginGA::authenticateUser in ./ga_login.class.php
- GoogleAuthenticator::authenticateUser in ./ga4php.php
- GoogleAuthenticator::resyncCode in ./ga4php.php
File
- ./ga4php.php, line 379
Class
- GoogleAuthenticator
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);
if (strlen($bin_counter) < 8) {
$bin_counter = str_repeat(chr(0), 8 - strlen($bin_counter)) . $bin_counter;
}
$hash = hash_hmac('sha1', $bin_counter, $key);
return str_pad($this
->oath_truncate($hash), 6, "0", STR_PAD_LEFT);
}