Class FOFEncryptTotp
This class provides an RFC6238-compliant Time-based One Time Passwords,
compatible with Google Authenticator (with PassCodeLength = 6 and TimePeriod =
30).
Methods summary
public
|
#
__construct( integer $timeStep = 30, integer $passCodeLength = 6, integer $secretLength = 10, Object $base32 = null )
Initialises an RFC6238-compatible TOTP generator. Please note that this class
does not implement the constraint in the last paragraph of §5.2 of RFC6238.
It's up to you to ensure that the same user/device does not retry validation
within the same Time Step.
Initialises an RFC6238-compatible TOTP generator. Please note that this class
does not implement the constraint in the last paragraph of §5.2 of RFC6238.
It's up to you to ensure that the same user/device does not retry validation
within the same Time Step.
Parameters
- $timeStep
integer - $timeStep The Time Step (in seconds). Use 30 to be compatible with Google
Authenticator.
- $passCodeLength
integer - $passCodeLength The generated passcode length. Default: 6 digits.
- $secretLength
integer - $secretLength The length of the secret key. Default: 10 bytes (80 bits).
- $base32
Object - $base32 The base32 en/decrypter
|
public
integer
|
#
getPeriod( integer|null $time = null )
Get the time period based on the $time timestamp and the Time Step defined.
If $time is skipped or set to null the current timestamp will be used.
Get the time period based on the $time timestamp and the Time Step defined.
If $time is skipped or set to null the current timestamp will be used.
Parameters
- $time
integer|null - $time Timestamp
Returns
integer - The time period since the UNIX Epoch
|
public
boolean
|
#
checkCode( string $secret, string $code )
Check is the given passcode $code is a valid TOTP generated using secret key
$secret
Check is the given passcode $code is a valid TOTP generated using secret key
$secret
Parameters
- $secret
string - $secret The Base32-encoded secret key
- $code
string - $code The passcode to check
Returns
boolean - True if the code is valid
|
public
string
|
#
getCode( string $secret, integer $time = null )
Gets the TOTP passcode for a given secret key $secret and a given UNIX
timestamp $time
Gets the TOTP passcode for a given secret key $secret and a given UNIX
timestamp $time
Parameters
- $secret
string - $secret The Base32-encoded secret key
- $time
integer - $time UNIX timestamp
Returns
string
|
protected
string
|
#
hashToInt( string $bytes, string $start )
Extracts a part of a hash as an integer
Extracts a part of a hash as an integer
Parameters
- $bytes
string - $bytes The hash
- $start
string - $start The char to start from (0 = first char)
Returns
string
|
public
string
|
#
getUrl( string $user, string $hostname, string $secret )
Returns a QR code URL for easy setup of TOTP apps like Google
Authenticator
Returns a QR code URL for easy setup of TOTP apps like Google
Authenticator
Parameters
- $user
string - $user User
- $hostname
string - $hostname Hostname
- $secret
string - $secret Secret string
Returns
string
|
public
string
|
#
generateSecret( )
Generates a (semi-)random Secret Key for TOTP generation
Generates a (semi-)random Secret Key for TOTP generation
Returns
string
|
Magic methods summary