leandrolugaresi / google-authenticator
PHP repository for Google Authenticator
Installs: 52 588
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 1
Forks: 3
Open Issues: 2
Requires
- php: >=5.3.3
- christian-riesen/base32: 1.2
- zendframework/zend-math: >=2.2
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is not auto-updated.
Last update: 2022-02-01 12:39:44 UTC
README
[DEPRECATED] use the antonioribeiro/google2fa instead!
Introduction
This is a module to integrate web sites with Google Authenticator.
Requirements
- ChristianRiesen/base32 (1.2)
- zendframework/zend-math (>2.2.*)
Installation
- Add this project in your composer.json:
"require": { "leandrolugaresi/google-authenticator": "1.0.*" }
- Now tell the composer to download the repository by running the command:
$ php composer.phar update
Usage
Step 1 - Register application
Show the QrCode and the form:
$googleAuth = new \GoogleAuthenticator\GoogleAuthenticator(); $googleAuth->setIssuer('YourApplicationName'); //save the secretKey to register after $_SESSION['secretKeyTemp'] = $googleAuth->getSecretKey(); // Show the qrcode to register //this param is an identifier of the user in this application echo $googleAuth->getQRCodeUrl($user->username.'@YourApplicationName');
Verify the code from form and save the secretKey of this user:
$google = new GoogleAuthenticator($_SESSION['secretKeyTemp']); $userSubmitCode = $_POST['codeFoo']; if ($google->verifyCode($userSubmitCode)) { //save the secretKey of this user }
Step 2 - Verify Code at login
$google = new GoogleAuthenticator($user->getSecretKey()); $userSubmitCode = $_POST['codeFoo']; // Verify Code if ($google->verifyCode($userSubmitCode)) { // OK - aloowed login }