Google Authenticator

Google Authenticator

Google Authenticator is an application that implements TOTP security tokens from RFC 6238 in mobile apps made by Google, sometimes branded "two-step authentication". Authenticator provides a six to eight digit one-time password users must provide in addition to their username and password to log into Google services or other sites. The Authenticator can also generate codes for third party applications, such as password managers or file hosting services. Previous versions of the software were open source.


  • Typical use case 1
  • Implementations 2
  • Technical description 3
    • Pseudocode for Time OTP 3.1
    • Pseudocode for Event/Counter OTP 3.2
  • Open Source status on Android 4
  • Usage 5
  • References 6
  • External links 7

Typical use case

Typically, users will install the Authenticator app on their smartphone. To log into a site or service that uses two-factor authentication, they provide user name and password to the site and run the Authenticator app which produces an additional six-digit one-time password. The user provides this to the site, the site checks it for correctness and authenticates the user.

For this to work, a set-up operation has to be performed ahead of time: the site provides a shared secret key to the user over a secure channel, to be stored in the Authenticator app. This secret key will be used for all future logins to the site.

With this kind of two-factor authentication, mere knowledge of username and password is not sufficient to break into a user's account. The attacker also needs knowledge of the shared secret or physical access to the device running the Authenticator app. An alternative route of attack is a man-in-the-middle attack: if the computer used for the login process is compromised by a trojan, then username, password and one-time password can be captured by the trojan, which can then initiate its own login session to the site or monitor and modify the communication between user and site.


Google provides Android,[1] BlackBerry and iOS,[2] versions of Authenticator. Several third party implementations are available.

  • Windows Phone 7.5/8: Authenticator Virtual TokenFactor
  • Windows Mobile: Google Authenticator for Windows Mobile
  • Java CLI: Authenticator.jar
  • Java GUI: JAuth
  • J2ME: gauthj2me lwuitgauthj2me Mobile-OTP (chinese only) totp-me
  • Palm OS: gauthj2me
  • Python: onetimepass
  • PHP: GoogleAuthenticator.php
  • Ruby: gem (third party implementation)
  • Rails: active_model_otp (third party implementation)
  • webOS: GAuth
  • Windows: gauth4win MOS Authenticator WinAuth
  • .NET: TwoStepsAuthenticator
  • HTML5: html5-google-authenticator
  • MeeGo/Harmattan (Nokia N9): GAuth
  • Sailfish OS: SGAuth
  • Apache: Google Authenticator Apache Module
  • PAM: Google Pluggable Authentication Module oauth-pam
  • Backend: LinOTP (Management Backend implemented in python)
  • Chrome/Chrome OS: Authenticator
  • iOS: OTP Auth

Technical description

The service provider generates an 80-bit secret key for each user. This is provided as a 16, 24 or 32 character base32 string or as a QR code. The client creates an HMAC-SHA1 using this secret key. The message that is HMAC-ed can be:

  • the number of 30 second periods having elapsed since the Unix epoch; or
  • the counter that is incremented with each new code.

A portion of the HMAC is extracted and converted to a 6 digit code.

Pseudocode for Time OTP

 function GoogleAuthenticatorCode(string secret)
     key := base32decode(secret)
     message := floor(current Unix time / 30)
     hash := HMAC-SHA1(key, message)
     offset := value of last nibble of hash
     truncatedHash := hash[offset..offset+3]  //4 bytes starting at the offset
     Set the first bit of truncatedHash to zero  //remove the most significant bit 
     code := truncatedHash mod 1000000
     pad code with 0 until length of code is 6
     return code 

Pseudocode for Event/Counter OTP

 function GoogleAuthenticatorCode(string secret)
     key := base32decode(secret)
     message := counter encoded on 8 bytes
     hash := HMAC-SHA1(key, message)
     offset := last nibble of hash
     truncatedHash := hash[offset..offset+3]  //4 bytes starting at the offset
     Set the first bit of truncatedHash to zero  //remove the most significant bit 
     code := truncatedHash mod 1000000
     pad code with 0 until length of code is 6
     return code 

Open Source status on Android

The Authenticator app as available on Google's Android app market is proprietary, as explained on the project's development page:

"This open source project allows you to download the code that powered version 2.21 of the application. Subsequent versions contain Google-specific workflows that are not part of the project."[3]

An independent fork of the Android version of the software named OTP Authenticator[4] has been created, which is based on the last version of the open source code that had been provided by Google. Another Open Source fork named FreeOTP[5] has been published by Red Hat.


Google Authenticator can be used for the following websites and applications:


  1. ^ Android version of Google Authenticator
  2. ^ iOS version of Google Authenticator
  3. ^ Open Source status of Google Authenticator on Android
  4. ^ OTP Authenticator, an Open Source fork of the Android app
  5. ^
  6. ^
  7. ^ Added security for your account
  8. ^ Update: Bitstamp adds support for two-factor authentication
  9. ^
  10. ^
  11. ^
  12. ^ bitcoin commodity exchange
  13. ^ CipherGraph adds Two-Factor Authentication to CipherGraph Cloud Access Gateway Cloud Security Solution
  14. ^
  15. ^
  16. ^ Dashlane Adds Two-Factor Authentication, a New Interface, and More (Lifehacker)
  17. ^ DigitalOcean Features
  18. ^ Enabling Multifactor Authentication
  19. ^ Dropbox with Google Authenticator
  20. ^
  21. ^ Use Facebook’s 2-factor Authentication with Third-Party TOTP Generators
  22. ^
  23. ^
  24. ^
  25. ^
  26. ^
  27. ^ LastPass with Google Authenticator
  28. ^ Linode Manager Two-Step Authentication
  29. ^ LinOTP LinOTP Management Backend
  30. ^ Login - Google Authenticator for Desktop (lightdm or gdm plugin) - Ask Ubuntu
  31. ^ Boost your account security thanks to Mt.Gox's new Security Center
  32. ^ Blog post about addition of TOTP authentication to Nearlyfreespeech
  33. ^
  34. ^
  35. ^
  36. ^
  37. ^
  38. ^

External links

  • Google Authenticator on Google Help
  • Google Authenticator open source project on Google Code
  • Google Authenticator implementation in Python on Stack Overflow
  • Google Authenticator Android package at the F-Droid repository