Auth
in package
Class Auth
Table of Contents
Properties
- $codeLength : int
- $initKey : string|null
- $lookup : array<string|int, mixed>
- $range : int
- $refreshSeconds : int
Methods
- __construct() : mixed
- Initialize the object and set up the lookup table Optionally the Initialization key
- base32_decode() : string
- Base32 decoding function
- buildLookup() : void
- Build the base32 lookup table
- generateCode() : string
- Generate a code/hash Useful for making Initialization codes
- generateOneTime() : string
- Generate a one-time code
- generateTimestamp() : int
- Generate the timestamp for the calculation
- getCodeLength() : int
- Get the current length for generated codes
- getInitKey() : string
- Get the current Initialization key
- getLookup() : array<string|int, mixed>
- Get the current lookup data set
- getQrCodeUrl() : string
- Returns a URL to QR code for embedding the QR code
- getRange() : int
- Get the current "range" value
- getRefresh() : int
- Get the number of seconds for code refresh currently set
- setCodeLength() : Auth
- Set the length of the generated codes
- setInitKey() : Auth
- Set the initialization key for the object
- setLookup() : Auth
- Set the contents of the internal lookup table
- setRange() : Auth
- Set the "range" value
- setRefresh() : Auth
- Set the number of seconds to refresh codes
- truncateHash() : string
- Truncate the given hash down to just what we need
- validateCode() : bool
- Validate the given code
Properties
$codeLength
private
int
$codeLength
= 6
The length of codes to generate
$initKey
private
string|null
$initKey
= null
Initialization key
$lookup
private
array<string|int, mixed>
$lookup
= []
Internal lookup table
$range
private
int
$range
= 2
Range plus/minus for "window of opportunity" on allowed codes
$refreshSeconds
private
int
$refreshSeconds
= 30
Seconds between key refreshes
Methods
__construct()
Initialize the object and set up the lookup table Optionally the Initialization key
public
__construct([string $initKey = null ]) : mixed
Parameters
- $initKey : string = null
-
Initialization key
base32_decode()
Base32 decoding function
public
base32_decode(string $hash) : string
Parameters
- $hash : string
-
The base32-encoded hash
Tags
Return values
string —Binary value of hash
buildLookup()
Build the base32 lookup table
public
buildLookup() : void
generateCode()
Generate a code/hash Useful for making Initialization codes
public
generateCode([int $length = 16 ]) : string
Parameters
- $length : int = 16
-
Length for the generated code
Return values
string —Generated code
generateOneTime()
Generate a one-time code
public
generateOneTime([string $initKey = null ][, string $timestamp = null ]) : string
Parameters
- $initKey : string = null
-
Initialization key [optional]
- $timestamp : string = null
-
Timestamp for calculation [optional]
Return values
string —Generated code/hash
generateTimestamp()
Generate the timestamp for the calculation
public
generateTimestamp() : int
Return values
int —Timestamp
getCodeLength()
Get the current length for generated codes
public
getCodeLength() : int
Return values
int —Code length
getInitKey()
Get the current Initialization key
public
getInitKey() : string
Return values
string —Initialization key
getLookup()
Get the current lookup data set
public
getLookup() : array<string|int, mixed>
Return values
array<string|int, mixed> —Lookup data
getQrCodeUrl()
Returns a URL to QR code for embedding the QR code
public
getQrCodeUrl(string $name, string $code) : string
Parameters
- $name : string
-
The name
- $code : string
-
The generated code
Return values
string —The URL to the QR code
getRange()
Get the current "range" value
public
getRange() : int
Return values
int —Range value
getRefresh()
Get the number of seconds for code refresh currently set
public
getRefresh() : int
Return values
int —Refresh in seconds
setCodeLength()
Set the length of the generated codes
public
setCodeLength(int $length) : Auth
Parameters
- $length : int
-
Code length
Return values
Auth —instance
setInitKey()
Set the initialization key for the object
public
setInitKey(string $key) : Auth
Parameters
- $key : string
-
Initialization key
Tags
Return values
Auth —instance
setLookup()
Set the contents of the internal lookup table
public
setLookup(array<string|int, mixed> $lookup) : Auth
Parameters
- $lookup : array<string|int, mixed>
-
Lookup data set
Tags
Return values
Auth —instance
setRange()
Set the "range" value
public
setRange(int $range) : Auth
Parameters
- $range : int
-
Range value
Return values
Auth —instance
setRefresh()
Set the number of seconds to refresh codes
public
setRefresh(int $seconds) : Auth
Parameters
- $seconds : int
-
Seconds to refresh
Tags
Return values
Auth —instance
truncateHash()
Truncate the given hash down to just what we need
public
truncateHash(string $hash) : string
Parameters
- $hash : string
-
Hash to truncate
Return values
string —Truncated hash value
validateCode()
Validate the given code
public
validateCode(string $code[, string $initKey = null ][, string $timestamp = null ][, int $range = null ]) : bool
Parameters
- $code : string
-
Code entered by user
- $initKey : string = null
-
Initialization key
- $timestamp : string = null
-
Timestamp for calculation
- $range : int = null
-
Seconds before/after to validate hash against
Tags
Return values
bool —Pass/fail of validation