TwoFactorAuth
in package
Table of Contents
- $_base32 : array<string|int, mixed>
- $_base32dict : string
- $_base32lookup : array<string|int, mixed>
- $_supportedalgos : array<string|int, mixed>
- $algorithm : string
- $digits : int
- $issuer : string
- $period : int
- $qrcodeprovider : IQRCodeProvider|null
- $rngprovider : IRNGProvider|null
- $timeprovider : ITimeProvider|null
- __construct() : mixed
- createSecret() : string
- Create a new secret
- ensureCorrectTime() : void
- Compare default timeprovider with specified timeproviders and ensure the time is within the specified number of seconds (leniency)
- getCode() : string
- Calculate the code with given secret and point in time
- getQRCodeImageAsDataUri() : string
- Get data-uri of QRCode
- getQrCodeProvider() : IQRCodeProvider
- getQRText() : string
- Builds a string to be encoded in a QR code
- getRngProvider() : IRNGProvider
- getTimeProvider() : ITimeProvider
- verifyCode() : bool
- Check if the code is correct. This will accept codes starting from ($discrepancy * $period) sec ago to ($discrepancy * period) sec from now
- base32Decode() : string
- codeEquals() : bool
- Timing-attack safe comparison of 2 codes (see http://blog.ircmaxell.com/2014/11/its-all-about-time.html)
- getTime() : int
- getTimeSlice() : int
Properties
$_base32
private
static array<string|int, mixed>
$_base32
$_base32dict
private
static string
$_base32dict
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567='
$_base32lookup
private
static array<string|int, mixed>
$_base32lookup
= array()
$_supportedalgos
private
static array<string|int, mixed>
$_supportedalgos
= array('sha1', 'sha256', 'sha512', 'md5')
$algorithm
private
string
$algorithm
$digits
private
int
$digits
$issuer
private
string
$issuer
$period
private
int
$period
$qrcodeprovider
private
IQRCodeProvider|null
$qrcodeprovider
= null
$rngprovider
private
IRNGProvider|null
$rngprovider
= null
$timeprovider
private
ITimeProvider|null
$timeprovider
= null
Methods
__construct()
public
__construct([string|null $issuer = null ][, int $digits = 6 ][, int $period = 30 ][, string $algorithm = 'sha1' ][, IQRCodeProvider|null $qrcodeprovider = null ][, IRNGProvider|null $rngprovider = null ][, ITimeProvider|null $timeprovider = null ]) : mixed
Parameters
- $issuer : string|null = null
- $digits : int = 6
- $period : int = 30
- $algorithm : string = 'sha1'
- $qrcodeprovider : IQRCodeProvider|null = null
- $rngprovider : IRNGProvider|null = null
- $timeprovider : ITimeProvider|null = null
Return values
mixed —createSecret()
Create a new secret
public
createSecret([int $bits = 80 ][, bool $requirecryptosecure = true ]) : string
Parameters
- $bits : int = 80
- $requirecryptosecure : bool = true
Return values
string —ensureCorrectTime()
Compare default timeprovider with specified timeproviders and ensure the time is within the specified number of seconds (leniency)
public
ensureCorrectTime([array<string|int, mixed>|null $timeproviders = null ][, int $leniency = 5 ]) : void
Parameters
- $timeproviders : array<string|int, mixed>|null = null
- $leniency : int = 5
Return values
void —getCode()
Calculate the code with given secret and point in time
public
getCode(string $secret[, int|null $time = null ]) : string
Parameters
- $secret : string
- $time : int|null = null
Return values
string —getQRCodeImageAsDataUri()
Get data-uri of QRCode
public
getQRCodeImageAsDataUri(string $label, string $secret[, mixed $size = 200 ]) : string
Parameters
- $label : string
- $secret : string
- $size : mixed = 200
Return values
string —getQrCodeProvider()
public
getQrCodeProvider() : IQRCodeProvider
Tags
Return values
IQRCodeProvider —getQRText()
Builds a string to be encoded in a QR code
public
getQRText(string $label, string $secret) : string
Parameters
- $label : string
- $secret : string
Return values
string —getRngProvider()
public
getRngProvider() : IRNGProvider
Tags
Return values
IRNGProvider —getTimeProvider()
public
getTimeProvider() : ITimeProvider
Tags
Return values
ITimeProvider —verifyCode()
Check if the code is correct. This will accept codes starting from ($discrepancy * $period) sec ago to ($discrepancy * period) sec from now
public
verifyCode(string $secret, string $code[, int $discrepancy = 1 ][, int|null $time = null ], int &$timeslice) : bool
Parameters
- $secret : string
- $code : string
- $discrepancy : int = 1
- $time : int|null = null
- $timeslice : int
Return values
bool —base32Decode()
private
base32Decode(string $value) : string
Parameters
- $value : string
Return values
string —codeEquals()
Timing-attack safe comparison of 2 codes (see http://blog.ircmaxell.com/2014/11/its-all-about-time.html)
private
codeEquals(string $safe, string $user) : bool
Parameters
- $safe : string
- $user : string
Return values
bool —getTime()
private
getTime([int|null $time = null ]) : int
Parameters
- $time : int|null = null
Return values
int —getTimeSlice()
private
getTimeSlice([int $time = null ], int $offset) : int
Parameters
- $time : int = null
- $offset : int