Skip to content

TOTPInterface

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

public setPeriod(positive-int $period): void

Parameters:

Parameter Type Description
$period positive-int

setEpoch

public setEpoch(0|positive-int $epoch): void

Parameters:

Parameter Type Description
$epoch 0|positive-int

now

Return the TOTP at the current time.

public now(): non-empty-string

getPeriod

Get the period of time for OTP generation (a non-null positive integer, in second).

public getPeriod(): positive-int

expiresIn

public expiresIn(): 0|positive-int

getEpoch

public getEpoch(): 0|positive-int

Inherited methods

createFromSecret

Create a OTP object from an existing secret.

public static createFromSecret(non-empty-string $secret): self
  • 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.

public static generate(): self
  • This method is static.

setSecret

public setSecret(non-empty-string $secret): void

Parameters:

Parameter Type Description
$secret non-empty-string

setDigits

public setDigits(positive-int $digits): void

Parameters:

Parameter Type Description
$digits positive-int

setDigest

public setDigest(non-empty-string $digest): void

Parameters:

Parameter Type Description
$digest non-empty-string

at

public at(0|positive-int $input): non-empty-string

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

public getSecret(): non-empty-string

Return Value:

The secret of the OTP


setLabel

public setLabel(non-empty-string $label): void

Parameters:

Parameter Type Description
$label non-empty-string The label of the OTP

getLabel

public getLabel(): non-empty-string|null

Return Value:

The label of the OTP


getIssuer

public getIssuer(): non-empty-string|null

Return Value:

The issuer


setIssuer

public setIssuer(non-empty-string $issuer): void

Parameters:

Parameter Type Description
$issuer non-empty-string

isIssuerIncludedAsParameter

public isIssuerIncludedAsParameter(): bool

Return Value:

If true, the issuer will be added as a parameter in the provisioning URI


setIssuerIncludedAsParameter

public setIssuerIncludedAsParameter(bool $issuer_included_as_parameter): void

Parameters:

Parameter Type Description
$issuer_included_as_parameter bool

getDigits

public getDigits(): positive-int

Return Value:

Number of digits in the OTP


getDigest

public getDigest(): non-empty-string

Return Value:

Digest algorithm used to calculate the OTP. Possible values are 'md5', 'sha1', 'sha256' and 'sha512'


getParameter

public getParameter(non-empty-string $parameter): mixed

Parameters:

Parameter Type Description
$parameter non-empty-string

hasParameter

public hasParameter(non-empty-string $parameter): bool

Parameters:

Parameter Type Description
$parameter non-empty-string

getParameters

public getParameters(): array<non-empty-string,mixed>

setParameter

public setParameter(non-empty-string $parameter, mixed $value): void

Parameters:

Parameter Type Description
$parameter non-empty-string
$value mixed

getProvisioningUri

Get the provisioning URI.

public getProvisioningUri(): non-empty-string

getQrCodeUri

Get the provisioning URI.

public getQrCodeUri(non-empty-string $uri, non-empty-string $placeholder): string

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