2017 © Pedro Peláez
 

library google-authenticator

Google authenticator (HOTP & TOTP)

image

xp-forge/google-authenticator

Google authenticator (HOTP & TOTP)

  • Thursday, November 16, 2017
  • by thekid
  • Repository
  • 2 Watchers
  • 0 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Google authenticator

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version, (*1)

Supports one-time passwords accordings (HOTP & TOTP) according to RFC 4226 and RFC 6238., (*2)

Working with one-time passwords

The following shows the API for time-based one-time passwords (TOTP):, (*3)

use com\google\authenticator\{TimeBased, Tolerance};
use util\Secret;

$secret= new Secret('2BX6RYQ4MD5M46KP');
$timebased= new TimeBased($secret);
$time= time();

// Get token for a given time
$token= $timebased->at($time);
$token= $timebased->current();

// Must match exactly
$verified= $timebased->verify($token, $time, Tolerance::$NONE);

// Allows previous and next
$verified= $timebased->verify($token);
$verified= $timebased->verify($token, $time);
$verified= $timebased->verify($token, $time, Tolerance::$PREVIOUS_AND_NEXT);

The following shows the API for counter-based one-time passwords (HOTP):, (*4)

use com\google\authenticator\{CounterBased, Tolerance};
use util\Secret;

$secret= new Secret('2BX6RYQ4MD5M46KP');
$counterbased= new CounterBased($secret);
$counter= 0;

// Get token for a given counter
$token= $counterbased->at($counter);

// Must match exactly
$verified= $counterbased->verify($token, $counter, Tolerance::$NONE);

// Allows previous and next
$verified= $counterbased->verify($token, $counter);
$verified= $counterbased->verify($token, $counter, Tolerance::$PREVIOUS_AND_NEXT);

Note: We use util.Secret so that in case of exceptions, the secret will not appear in stack traces., (*5)

Creating secrets

As an issuer of OTPs, you need to create random secrets in order to seed both client and server. Using the provisioningUri() method, you can fetch the URIs used to configure the clients., (*6)

use com\google\authenticator\{CounterBased, TimeBased, Secrets};

$random= Secrets::random();

// HOTP, otpauth://hotp/{account}?secret={secret}&counter={counter}
$counterbased= new CounterBased($random);
$uri= $counterbased->provisioningUri($account);             // Start with counter= 0
$uri= $counterbased->provisioningUri($account, $initial);   // Start with counter= $initial

// TOTP, otpauth://totp/{account}?secret={secret}
$timebased= new TimeBased($random);
$uri= $timebased->provisioningUri($account);

// Pass a map of string to append additional parameters
$uri= $timebased->provisioningUri($account, ['issuer' => 'ACME Co']);

// Pass an array to namespace the account, yields "ACME%20Co:user@example.com"
$uri= $timebased->provisioningUri(['ACME Co', 'user@example.com']);

The Versions

16/11 2017

dev-master

9999999-dev http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

16/11 2017

v3.1.0

3.1.0.0 http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/11 2017

v3.0.0

3.0.0.0 http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

21/02 2016

v2.0.0

2.0.0.0 http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

23/01 2016

v1.0.1

1.0.1.0 http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

14/12 2015

v1.0.0

1.0.0.0 http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

12/02 2015

v0.2.1

0.2.1.0 http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

07/02 2015

v0.2.0

0.2.0.0 http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

25/01 2015

v0.1.0

0.1.0.0 http://xp-framework.net/

Google authenticator (HOTP & TOTP)

  Sources   Download

BSD-3-Clause

The Requires

 

module xp