public function GoogleAuthenticator::oathHotp in Google Authenticator login 7
Create HOTP.
3 calls to GoogleAuthenticator::oathHotp()
- GALoginGA::authenticateUser in ./
ga_login.class.php - Authenticate a user.
- GoogleAuthenticator::authenticateUser in ./
ga4php.php - Authenticate a user using a code.
- GoogleAuthenticator::resyncCode in ./
ga4php.php - Resync codes.
File
- ./
ga4php.php, line 387 - Abstract GoogleAuthenticator class.
Class
- GoogleAuthenticator
- @file Abstract GoogleAuthenticator class.
Code
public function oathHotp($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
->oathTruncate($hash), 6, "0", STR_PAD_LEFT);
}