TwoFactorAuthAuthenticator
in package
Class representing a two-factor-authorization handler Originally created by Michael Kliewe and adopted by Gambio GmbH
Table of Contents
- $_codeLength : mixed
- createSecret() : string
- Create new secret.
- currentTimestamp() : IntType
- Return the current timestamp
- getCode() : string
- Calculate the code, with given secret and point in time.
- setCodeLength() : $this
- 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
$_codeLength
protected
mixed
$_codeLength
= 6
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 —currentTimestamp()
Return the current timestamp
public
static currentTimestamp() : IntType
Return values
IntType —Timestamp
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 —setCodeLength()
Set the code length, should be >=6.
public
setCodeLength(int $length) : $this
Parameters
- $length : int
Return values
$this —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( $secret) : bool|string
Parameters
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