Totp
This class provides an RFC6238-compliant Time-based One Time Passwords, compatible with Google Authenticator (with PassCodeLength = 6 and TimePeriod = 30).
since |
4.0.0 |
---|---|
package |
Joomla CMS |
Methods
__construct
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.
__construct( timeStep = 30, passCodeLength = 6, secretLength = 10, base32 = null) :
Arguments
- timeStep
int
The Time Step (in seconds). Use 30 to be compatible with Google Authenticator.- passCodeLength
int
The generated passcode length. Default: 6 digits.- secretLength
int
The length of the secret key. Default: 10 bytes (80 bits).- base32
object
The base32 en/decrypter
Response
mixed
checkCode
Check is the given passcode $code is a valid TOTP generated using secret key $secret
checkCode( secret, code) :
Arguments
- secret
string
The Base32-encoded secret key- code
string
The passcode to check
Response
bool
True if the code is valid
generateSecret
Generates a (semi-)random Secret Key for TOTP generation
generateSecret() :
note |
Since 3.9.25 we use the secure method "random_bytes" over the original insecure "rand" function. The random_bytes function has been backported to outdated PHP versions by the core shipped library paragonie/random_compat |
---|
Response
string
getCode
Gets the TOTP passcode for a given secret key $secret and a given UNIX timestamp $time
getCode( secret, time = null) :
Arguments
- secret
string
The Base32-encoded secret key- time
int
UNIX timestamp
Response
string
getPeriod
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.
getPeriod(int|null time = null) :
Arguments
- time
int|null
Timestamp
Response
int
The time period since the UNIX Epoch
getUrl
Returns a QR code URL for easy setup of TOTP apps like Google Authenticator
getUrl( user, hostname, secret) :
Arguments
- user
string
User- hostname
string
Hostname- secret
string
Secret string
Response
string
hashToInt
Extracts a part of a hash as an integer
hashToInt( bytes, start) :
Arguments
- bytes
string
The hash- start
string
The char to start from (0 = first char)
Response
string
Properties
_passCodeLength
Passcode length
Type(s)
int
_pinModulo
Pin modulo
Type(s)
int
_secretLength
The length of the secret in bytes.
RFC 4226: "The length of the shared secret MUST be at least 128 bits. This document RECOMMENDs a shared secret length of 160 bits." The original value was 10 bytes (80 bits) this value has been increased to 20 (160 bits) with Joomla! 3.9.25
Type(s)
int
_timeStep
Timestep
Type(s)
int
_base32
Base32
Type(s)
int