google-authenticator
[DEPRECATED] use the antonioribeiro/google2fa instead!, (*1)
, (*2)
Introduction
This is a module to integrate web sites with Google Authenticator., (*3)
Requirements
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:, (*4)
$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:, (*5)
$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
}