public function GoogleAuthenticator::oathTruncate in Google Authenticator login 7
Truncate.
1 call to GoogleAuthenticator::oathTruncate()
- GoogleAuthenticator::oathHotp in ./
ga4php.php - Create HOTP.
File
- ./
ga4php.php, line 409 - Abstract GoogleAuthenticator class.
Class
- GoogleAuthenticator
- @file Abstract GoogleAuthenticator class.
Code
public function oathTruncate($hash, $length = 6) {
// Convert to dec,
foreach (str_split($hash, 2) as $hex) {
$hmac_result[] = hexdec($hex);
}
// Find offset.
$offset = $hmac_result[19] & 0xf;
// Algorithm from RFC.
return (($hmac_result[$offset + 0] & 0x7f) << 24 | ($hmac_result[$offset + 1] & 0xff) << 16 | ($hmac_result[$offset + 2] & 0xff) << 8 | $hmac_result[$offset + 3] & 0xff) % pow(10, $length);
}