TOTPInterface
- Full name:
\OTPHP\TOTPInterface
- Parent interfaces:
\OTPHP\OTPInterface
Constants
Constant | Visibility | Type | Value |
---|---|---|---|
DEFAULT_PERIOD |
public | 30 | |
DEFAULT_EPOCH |
public | 0 |
Methods
create
Create a new TOTP object.
public static create(null|non-empty-string $secret = null, positive-int $period = self::DEFAULT_PERIOD, non-empty-string $digest = self::DEFAULT_DIGEST, positive-int $digits = self::DEFAULT_DIGITS): self
If the secret is null, a random 64 bytes secret will be generated.
-
This method is static.
-
Warning: this method is deprecated. This means that this method will likely be removed in a future version.
Parameters:
Parameter | Type | Description |
---|---|---|
$secret |
null|non-empty-string | |
$period |
positive-int | |
$digest |
non-empty-string | |
$digits |
positive-int |
setPeriod
Parameters:
Parameter | Type | Description |
---|---|---|
$period |
positive-int |
setEpoch
Parameters:
Parameter | Type | Description |
---|---|---|
$epoch |
0|positive-int |
now
Return the TOTP at the current time.
getPeriod
Get the period of time for OTP generation (a non-null positive integer, in second).
expiresIn
getEpoch
Inherited methods
createFromSecret
Create a OTP object from an existing secret.
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$secret |
non-empty-string |
generate
Create a new OTP object. A random 64 bytes secret will be generated.
- This method is static.
setSecret
Parameters:
Parameter | Type | Description |
---|---|---|
$secret |
non-empty-string |
setDigits
Parameters:
Parameter | Type | Description |
---|---|---|
$digits |
positive-int |
setDigest
Parameters:
Parameter | Type | Description |
---|---|---|
$digest |
non-empty-string |
at
Parameters:
Parameter | Type | Description |
---|---|---|
$input |
0|positive-int |
Return Value:
Return the OTP at the specified timestamp
verify
Verify that the OTP is valid with the specified input. If no input is provided, the input is set to a default value or false is returned.
public verify(non-empty-string $otp, null|0|positive-int $input = null, null|0|positive-int $window = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$otp |
non-empty-string | |
$input |
null|0|positive-int | |
$window |
null|0|positive-int |
getSecret
Return Value:
The secret of the OTP
setLabel
Parameters:
Parameter | Type | Description |
---|---|---|
$label |
non-empty-string | The label of the OTP |
getLabel
Return Value:
The label of the OTP
getIssuer
Return Value:
The issuer
setIssuer
Parameters:
Parameter | Type | Description |
---|---|---|
$issuer |
non-empty-string |
isIssuerIncludedAsParameter
Return Value:
If true, the issuer will be added as a parameter in the provisioning URI
setIssuerIncludedAsParameter
Parameters:
Parameter | Type | Description |
---|---|---|
$issuer_included_as_parameter |
bool |
getDigits
Return Value:
Number of digits in the OTP
getDigest
Return Value:
Digest algorithm used to calculate the OTP. Possible values are 'md5', 'sha1', 'sha256' and 'sha512'
getParameter
Parameters:
Parameter | Type | Description |
---|---|---|
$parameter |
non-empty-string |
hasParameter
Parameters:
Parameter | Type | Description |
---|---|---|
$parameter |
non-empty-string |
getParameters
setParameter
Parameters:
Parameter | Type | Description |
---|---|---|
$parameter |
non-empty-string | |
$value |
mixed |
getProvisioningUri
Get the provisioning URI.
getQrCodeUri
Get the provisioning URI.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri |
non-empty-string | The Uri of the QRCode generator with all parameters. This Uri MUST contain a placeholder that will be replaced by the method. |
$placeholder |
non-empty-string | the placeholder to be replaced in the QR Code generator URI |
Automatically generated on 2025-03-18