PHP code example of vinyvicente / google-authenticator
1. Go to this page and download the library: Download vinyvicente/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/ */
vinyvicente / 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 - allowed 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.