2017 © Pedro Peláez
 

library otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

image

christian-riesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  • Tuesday, July 10, 2018
  • by ChristianRiesen
  • Repository
  • 4 Watchers
  • 66 Stars
  • 149,042 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 20 Forks
  • 3 Open issues
  • 16 Versions
  • 9 % Grown

The README.md

One Time Passwords

Build Status, (*1)

Did you like this? Flattr it:, (*2)

Flattr otp, (*3)

Installation

Use composer and require the library in your composer.json, (*4)

{
    "require": {
        "christian-riesen/otp": "^2.0",
    }
}

Usage

<?php

use Otp\Otp;
use Otp\GoogleAuthenticator;
use ParagonIE\ConstantTime\Encoding;

// Get a Pseudo Secret
// Defaults to 16 characters
$secret = GoogleAuthenticator::generateRandom();

// Url for the QR code
// Using totp method
$url = GoogleAuthenticator::getQrCodeUrl('totp', 'Label like user@host.com', $secret);

// Save the secret with the users account
// Display QR Code to the user

// Now how to check
$otp = new Otp();

// $key is a 6 digit number, coming from the User
// Assuming this is present and sanitized
// Allows for a 1 code time drift by default
// Third parameter can alter that behavior
if ($otp->checkTotp(Encoding::base32DecodeUpper($secret), $key)) {
    // Correct key
    // IMPORTANT! Note this key as being used
    // so nobody could launch a replay attack.
    // Cache that for the next minutes and you
    // should be good.
} else {
    // Wrong key
}

// Just to create a key for display (testing)
$key = $otp->totp(Encoding::base32DecodeUpper($secret));

Sample script in example folder. Requires sessions to work (for secret storage)., (*5)

Class Otp

Implements hotp according to RFC4226 and totp according to RFC6238 (only sha1, sha256 and sha512 algorithms). Once you have a secret, you can use it directly in this class to create the passwords themselves (mainly for debugging use) or use the check functions to safely check the validity of the keys. The checkTotp function also includes a helper to battle timedrift., (*6)

Class GoogleAuthenticator

Static function class to generate a correct url for the QR code, so you can easily scan it with your device. Google Authenticator is available as an application for iPhone and Android. This removes the burden to create such an app from the developers of websites by using this set of classes., (*7)

There are also older open source versions of the Google Authenticator app for both iPhone and Android., (*8)

About

Requirements

PHP >= 5.4.0, (*9)

Uses paragonie/random_compat and paragonie/constant_time_encoding., (*10)

If you want to run the tests, PHPUnit >= 4.8.35 is required., (*11)

Author

Christian Riesen chris.riesen@gmail.com http://christianriesen.com, (*12)

Acknowledgements

The classes have been inspired by many different places that were talking about otp and Google Authenticator. Thank you all for your help., (*13)

Project setup ideas blatantly taken from https://github.com/Seldaek/monolog, (*14)

The Versions

10/07 2018

dev-master

9999999-dev https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

10/07 2018

2.6.1

2.6.1.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

04/05 2018

2.6.0

2.6.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

14/12 2017

2.5.0

2.5.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

16/03 2017

2.4.0

2.4.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

08/01 2017

2.3.0

2.3.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

10/06 2016

2.2.0

2.2.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

09/06 2016

2.1.0

2.1.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

02/06 2016

2.0.0

2.0.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

The Development Requires

otp totp hotp googleauthenticator rfc4226 rfc6238

08/10 2015

1.4.3

1.4.3.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

otp totp hotp googleauthenticator rfc4226 rfc6238

27/07 2015

1.4.2

1.4.2.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

otp totp hotp googleauthenticator rfc4226 rfc6238

20/04 2015

1.4.1

1.4.1.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

otp totp hotp googleauthenticator rfc4226 rfc6238

12/02 2015

1.4

1.4.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

otp totp hotp googleauthenticator rfc4226 rfc6238

21/08 2014

1.3

1.3.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

otp totp hotp googleauthenticator rfc4226 rfc6238

03/07 2013

1.2

1.2.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

otp totp hotp googleauthenticator rfc4226 rfc6238

29/01 2013

1.1

1.1.0.0 https://github.com/ChristianRiesen/otp

One Time Passwords, hotp and totp according to RFC4226 and RFC6238

  Sources   Download

MIT

The Requires

 

otp totp hotp googleauthenticator rfc4226 rfc6238