2017 © Pedro Peláez
 

library two-factor-auth

PHP Implementation of RFC 6238 used by the Google Authenticator Token Generator

image

mindgruve/two-factor-auth

PHP Implementation of RFC 6238 used by the Google Authenticator Token Generator

  • Thursday, March 9, 2017
  • by mindgruve
  • Repository
  • 4 Watchers
  • 1 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Two-Factor-Authentication

This PHP Library implements TOTP algorithm popularized by GoogleAuthenticator. It provides a simple, secure, and user-friendly 2-Factor-Authentication scheme., (*1)

Algorithm

The Time-Based One-Time Password Algorithm is described in RFC 26238 is located at https://tools.ietf.org/html/rfc6238, (*2)

Generating Secrets

  1. Have your users download the GoogleAuthenticator app to their smart phone. Links to Android Play Store and Apple App Store, (*3)

  2. Generate a Secret for each user and store it in your application, (*4)

    use Mindgruve\TwoFactorAuth\Secret;
    $secret = new Secret();
    // Secrets can be Serialized to a Base32 String
    $serializedSecret = $secret->asBase32();
    // Save this $serializedSecret in your application for this user   
  3. Have your user load the secret into GoogleAuthenticator., (*5)

    use Mindgruve\TwoFactorAuth\Secret;
    $secret = new Secret();
    /**
     * Display a QR code for users to scan
     */
    <img src="<?php echo $secret->getGoogleQRCodeUrl(); ?>">
    /**
     *  Display the secret for users to enter manually.
     */
    echo $secret->asBase32();
  4. GoogleAuthenticator will now generate a new token every 30 seconds for your user, (*6)

Validating Tokens

When your user logs in, prompt the user for a token. The user opens their GoogleAuthenticator and enters in the token shown on their screen, which regenerates every 30 seconds. To validate the token, you load the user's secret (from your database for instance) and use the helper function isValidToken() to validate the user supplied token., (*7)

    use Mindgruve\TwoFactorAuth\Authenticator;
    use Mindgruve\TwoFactorAuth\Secret;
    use Mindgruve\TwoFactorAuth\Token;

    /**
     * Load the $serializedSecret for the user
     * The $tokenString is value submitted by the user
     */
     $secret = new Secret($serializedSecret);
     $token = new Token($tokenString);
     $authenticator = new Authenticator();
     if($authenticator->isValidToken($secret, $token)){
        // access granted
     } else {
        // access denied
     }

Running tests

php vendor/bin/phpunit src, (*8)

The Versions

09/03 2017

dev-master

9999999-dev

PHP Implementation of RFC 6238 used by the Google Authenticator Token Generator

  Sources   Download

MIT

The Requires

 

The Development Requires

09/03 2017

1.0.0

1.0.0.0

PHP Implementation of RFC 6238 used by the Google Authenticator Token Generator

  Sources   Download

MIT

The Requires

 

The Development Requires