Google Authenticator is a mini PHP library for implementing Multi-Factor Authentication by utilizing Google's Authenticator App. It was written to simplify the usually complicated implementation process.
Following specifications were referenced:
- RFC 4226 - HMAC-Based One-Time Password Algorithm
- RFC 6238 - TOTP: Time-Based One-Time Password Algorithm
- RFC 6287 - OCRA: OATH Challenge-Response Algorithm
Song of the project: Iron Maiden - The Trooper
I use a 3-digit Semantic Versioning identifier, for example 1.0.2. These digits have the following meaning:
- The first digit (1) specifies the MAJOR version number.
- The second digit (0) specifies the MINOR version number.
- The third digit (2) specifies the PATCH version number.
Complete documentation can be found by following the link above.
Following examples should be more then enough to get you started. I tried my best to make them as simple as possible so that everyone, even junior developers, can successfully use them for implementing two-factor authentication.
- Creating a Secret
- Secret Creation Methods
- Setting Existing Secrets
- Creating an Account
- Account Management
- QR Codes
- Code Validation
For additional examples please review the official project's wiki.
You only need to have PHP >=7.0 available on your system to use Google Authenticator in your application. However, for running unit tests, you need to have the following extensions installed:
There's two ways you can add Google Authenticator library to your project:
- Copying files from the "source" directory to your project and requiring the "Autoload.php" script (this includes doing the same for project's dependencies ex. Encoders)
- Via Composer, by executing the command below
composer require jocic/google-authenticator 1.0.0
Following unit tests are available:
- Essentials - Tests for library's essentials ex. Autoloader, Base 32 encoder, etc.
- QR Generators - Tests for available QR code generators in the library.
- Elements - Tests for library's core elements ex. Secret, Account, etc.
You can execute them easily from the terminal like in the example below.
bash ./scripts/phpunit.sh --testsuite essentials bash ./scripts/phpunit.sh --testsuite qr-generators bash ./scripts/phpunit.sh --testsuite elements
Please don’t forget to install necessary dependencies before attempting to do the God's work above. They may be important.
bash ./scripts/composer.sh install
Please review the following documents if you are planning to contribute to the project:
My hourly rate is fairly reasonable so, if you need help with integrating Google Authenticator to your existing project, feel free to contact me via the email below.
Integration inquiries: firstname.lastname@example.org
Please don't hesitate to contact me if you have any questions, ideas, or concerns.
My Twitter account is: @jocic_91
My support E-Mail address is: email@example.com
Copyright & License
Copyright (C) 2018 Đorđe Jocić
Licensed under the MIT license.