PHP code example of leandrolugaresi / google-authenticator
1. Go to this page and download the library: Download leandrolugaresi/google-authenticator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
leandrolugaresi / google-authenticator example snippets
$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');
$google = new GoogleAuthenticator($_SESSION['secretKeyTemp']);
$userSubmitCode = $_POST['codeFoo'];
if ($google->verifyCode($userSubmitCode)) {
//save the secretKey of this user
}
$google = new GoogleAuthenticator($user->getSecretKey());
$userSubmitCode = $_POST['codeFoo'];
// Verify Code
if ($google->verifyCode($userSubmitCode)) {
// OK - aloowed login
}
bash
$ php composer.phar update
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.