PHP repository for Google Authenticator

v1.1 2018-11-07 14:01 UTC

This package is auto-updated.

Last update: 2024-02-08 06:40:21 UTC



This is a module to integrate web sites with Google Authenticator.



  1. Add this project in your composer.json:
    "require": {
        "vinyvicente/google-authenticator": "1.1"
  1. Now tell the composer to download the repository by running the command:
    $ php composer.phar update


###Step 1 - Register application

Show the QrCode and the form:

    $googleAuth = new \GoogleAuthenticator\GoogleAuthenticator();
    //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 - allowed login