◆ __construct()
__construct |
( |
|
$timeStep = 30 , |
|
|
|
$passCodeLength = 6 , |
|
|
|
$secretLength = 10 , |
|
|
|
$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.
- Paramètres
-
int | $timeStep | The Time Step (in seconds). Use 30 to be compatible with Google Authenticator. |
int | $passCodeLength | The generated passcode length. Default: 6 digits. |
int | $secretLength | The length of the secret key. Default: 10 bytes (80 bits). |
Object | $base32 | The base32 en/decrypter |
◆ checkCode()
checkCode |
( |
|
$secret, |
|
|
|
$code |
|
) |
| |
Check is the given passcode $code is a valid TOTP generated using secret key $secret
- Paramètres
-
string | $secret | The Base32-encoded secret key |
string | $code | The passcode to check |
- Renvoie
- boolean True if the code is valid
Références $i.
◆ generateSecret()
Generates a (semi-)random Secret Key for TOTP generation
- Renvoie
- string
- 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
Références FOFEncryptBase32\encode().
◆ getCode()
getCode |
( |
|
$secret, |
|
|
|
$time = null |
|
) |
| |
Gets the TOTP passcode for a given secret key $secret and a given UNIX timestamp $time
- Paramètres
-
string | $secret | The Base32-encoded secret key |
int | $time | UNIX timestamp |
- Renvoie
- string
Références $hash, et $offset.
◆ getPeriod()
getPeriod |
( |
|
$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.
- Paramètres
-
- Renvoie
- int The time period since the UNIX Epoch
◆ getUrl()
getUrl |
( |
|
$user, |
|
|
|
$hostname, |
|
|
|
$secret |
|
) |
| |
Returns a QR code URL for easy setup of TOTP apps like Google Authenticator
- Paramètres
-
string | $user | User |
string | $hostname | Hostname |
string | $secret | Secret string |
- Renvoie
- string
Références $url, et $user.
◆ hashToInt()
hashToInt |
( |
|
$bytes, |
|
|
|
$start |
|
) |
| |
|
protected |
Extracts a part of a hash as an integer
- Paramètres
-
string | $bytes | The hash |
string | $start | The char to start from (0 = first char) |
- Renvoie
- string
Références $input, et $start.
◆ $_base32
◆ $_passCodeLength
◆ $_pinModulo
◆ $_secretLength
◆ $_timeStep
La documentation de cette classe a été générée à partir du fichier suivant :