Implementing TOTP Two Factor Authentication for Google Authenticator with PHP & AJAX

Опубликовано: 20 Февраль 2026
на канале: HazardEdit
13,982
140

What is TOTP?
TOTP is a short form for Time-based One-time Password (usually called Token) which is password that can only be used once and is only valid to be used in a defined time range. Usually TOTP generators generate new passwords every defined number of seconds or minutes.

What is Google Authenticator?
Google Authenticator is a TOTP/HOTP generator you can freely use for your software, app or website authentication.

How does it work?
A simplified explanation would be, both google authenticator app and your authentication program know the same secret key and can compute the same token for a certain range in time based on this secret key.
A more technical explanation can be read here: https://security.stackexchange.com/qu...

Getting Started
To get started you will have to download the Google Authenticator app to your smartphone or tablet etc.
In this implementation example I will be using a PHP Framework by Michael Kliewe (PHPGangsta). From my point of view the framework is lightweight and just perfect for this example. I will not be changing the author’s initial code.
The author has stored the Framework on his github repo. Feel free to download in order to follow along. https://github.com/PHPGangsta/GoogleA...

#Social
Twitter:   / hazardedit  
Facebook:   / hazardedit  

#Messenger
Skype: hazardedit

Email: [email protected]