Documentation

GoogleAuthenticator
in package

PHP Class for handling Google Authenticator 2-factor authentication.

Tags
author

Michael Kliewe

copyright

2012 Michael Kliewe

license

http://www.opensource.org/licenses/bsd-license.php BSD License

link
http://www.phpgangsta.de/

Table of Contents

Properties

$_codeLength  : mixed

Methods

createSecret()  : string
Create new secret.
getCode()  : string
Calculate the code, with given secret and point in time.
getQRCodeGoogleUrl()  : string
Get QR-Code URL for image, from google charts.
setCodeLength()  : PHPGangsta_GoogleAuthenticator
Set the code length, should be >=6.
verifyCode()  : bool
Check if the code is correct. This will accept codes starting from $discrepancy*30sec ago to $discrepancy*30sec from now.
_base32Decode()  : bool|string
Helper class to decode base32.
_getBase32LookupTable()  : array<string|int, mixed>
Get array with all 32 characters for decoding from/encoding to base32.
timingSafeEquals()  : bool
A timing safe equals comparison more info here: http://blog.ircmaxell.com/2014/11/its-all-about-time.html.

Properties

Methods

createSecret()

Create new secret.

public createSecret([int $secretLength = 16 ]) : string

16 characters, randomly chosen from the allowed base32 characters.

Parameters
$secretLength : int = 16
Return values
string

getCode()

Calculate the code, with given secret and point in time.

public getCode(string $secret[, int|null $timeSlice = null ]) : string
Parameters
$secret : string
$timeSlice : int|null = null
Return values
string

getQRCodeGoogleUrl()

Get QR-Code URL for image, from google charts.

public getQRCodeGoogleUrl(string $name, string $secret[, string $title = null ][, array<string|int, mixed> $params = array() ]) : string
Parameters
$name : string
$secret : string
$title : string = null
$params : array<string|int, mixed> = array()
Return values
string

setCodeLength()

Set the code length, should be >=6.

public setCodeLength(int $length) : PHPGangsta_GoogleAuthenticator
Parameters
$length : int
Return values
PHPGangsta_GoogleAuthenticator

verifyCode()

Check if the code is correct. This will accept codes starting from $discrepancy*30sec ago to $discrepancy*30sec from now.

public verifyCode(string $secret, string $code[, int $discrepancy = 1 ][, int|null $currentTimeSlice = null ]) : bool
Parameters
$secret : string
$code : string
$discrepancy : int = 1

This is the allowed time drift in 30 second units (8 means 4 minutes before or after)

$currentTimeSlice : int|null = null

time slice if we want use other that time()

Return values
bool

_base32Decode()

Helper class to decode base32.

protected _base32Decode(mixed $secret) : bool|string
Parameters
$secret : mixed
Return values
bool|string

_getBase32LookupTable()

Get array with all 32 characters for decoding from/encoding to base32.

protected _getBase32LookupTable() : array<string|int, mixed>
Return values
array<string|int, mixed>

timingSafeEquals()

A timing safe equals comparison more info here: http://blog.ircmaxell.com/2014/11/its-all-about-time.html.

private timingSafeEquals(string $safeString, string $userString) : bool
Parameters
$safeString : string

The internal (safe) value to be checked

$userString : string

The user submitted (unsafe) value

Return values
bool

True if the two strings are identical


        
On this page

Search results