Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250711) (9addea9f0ac)
OTPHP\TOTP Class Reference
Inheritance diagram for OTPHP\TOTP:
OTPHP\OTP OTPHP\TOTPInterface OTPHP\OTPInterface OTPHP\OTPInterface

Public Member Functions

 __construct (string $secret, ?ClockInterface $clock=null)
 
 at (int $input)
 The OTP at the specified input.
 
 expiresIn ()
 
 getDigest ()
 
 getDigits ()
 
 getEpoch ()
 
 getIssuer ()
 
 getLabel ()
 
 getParameter (string $parameter)
 
 getParameters ()
 
 getPeriod ()
 Get the period of time for OTP generation (a non-null positive integer, in second).
 
 getProvisioningUri ()
 Get the provisioning URI.
 
 getQrCodeUri (string $uri, string $placeholder)
 Get the provisioning URI.
 
 getSecret ()
 
 hasParameter (string $parameter)
 
 isIssuerIncludedAsParameter ()
 
 now ()
 Return the TOTP at the current time.
 
 setDigest (string $digest)
 
 setDigits (int $digits)
 
 setEpoch (int $epoch)
 
 setIssuer (string $issuer)
 
 setIssuerIncludedAsParameter (bool $issuer_included_as_parameter)
 
 setLabel (string $label)
 
 setParameter (string $parameter, mixed $value)
 
 setPeriod (int $period)
 
 setSecret (string $secret)
 
 verify (string $otp, null|int $timestamp=null, null|int $leeway=null)
 If no timestamp is provided, the OTP is verified at the actual timestamp.
 

Static Public Member Functions

static create (null|string $secret=null, int $period=self::DEFAULT_PERIOD, string $digest=self::DEFAULT_DIGEST, int $digits=self::DEFAULT_DIGITS, int $epoch=self::DEFAULT_EPOCH, ?ClockInterface $clock=null)
 
static create (null|string $secret=null, int $period=self::DEFAULT_PERIOD, string $digest=self::DEFAULT_DIGEST, int $digits=self::DEFAULT_DIGITS)
 
static createFromSecret (string $secret)
 
static createFromSecret (string $secret, ?ClockInterface $clock=null)
 
static generate ()
 Create a new OTP object.
 
static generate (?ClockInterface $clock=null)
 

Public Attributes

const DEFAULT_DIGEST = 'sha1'
 
const DEFAULT_DIGITS = 6
 
const DEFAULT_EPOCH = 0
 
const DEFAULT_PERIOD = 30
 

Protected Member Functions

 compareOTP (string $safe, string $user)
 
 filterOptions (array &$options)
 
 generateOTP (int $input)
 The OTP at the specified input.
 
 generateURI (string $type, array $options)
 
 getParameterMap ()
 

Static Protected Member Functions

static generateSecret ()
 

Member Function Documentation

◆ at()

OTPHP\TOTP::at ( int $input)

The OTP at the specified input.

Parameters
0 | positive-int$input

Reimplemented from OTPHP\OTP.

◆ compareOTP()

OTPHP\OTP::compareOTP ( string $safe,
string $user )
protectedinherited
Parameters
non-empty-string$safe
non-empty-string$user

◆ expiresIn()

OTPHP\TOTP::expiresIn ( )

Implements OTPHP\TOTPInterface.

◆ filterOptions()

OTPHP\TOTP::filterOptions ( array & $options)
protected
Parameters
array<non-empty-string,mixed>$options

Reimplemented from OTPHP\OTP.

◆ generate()

static OTPHP\OTPInterface::generate ( )
staticinherited

Create a new OTP object.

A random 64 bytes secret will be generated.

◆ generateOTP()

OTPHP\OTP::generateOTP ( int $input)
protectedinherited

The OTP at the specified input.

Parameters
0 | positive-int$input
Return values
non-empty-string

◆ generateSecret()

static OTPHP\OTP::generateSecret ( )
staticfinalprotectedinherited
Return values
non-empty-string

◆ generateURI()

OTPHP\OTP::generateURI ( string $type,
array $options )
protectedinherited
Parameters
non-empty-string$type
array<non-empty-string,mixed>$options
Return values
non-empty-string

◆ getDigest()

OTPHP\OTPInterface::getDigest ( )
inherited
Return values
non-empty-stringDigest algorithm used to calculate the OTP. Possible values are 'md5', 'sha1', 'sha256' and 'sha512'

◆ getDigits()

OTPHP\OTPInterface::getDigits ( )
inherited
Return values
positive-intNumber of digits in the OTP

◆ getEpoch()

OTPHP\TOTP::getEpoch ( )

Implements OTPHP\TOTPInterface.

◆ getIssuer()

OTPHP\OTPInterface::getIssuer ( )
inherited
Return values
non-empty-string|nullThe issuer

◆ getLabel()

OTPHP\OTPInterface::getLabel ( )
inherited
Return values
non-empty-string|nullThe label of the OTP

◆ getParameter()

OTPHP\OTPInterface::getParameter ( string $parameter)
inherited
Parameters
non-empty-string$parameter

◆ getParameterMap()

OTPHP\TOTP::getParameterMap ( )
protected
Return values
array<non-empty-string,callable>

◆ getParameters()

OTPHP\OTPInterface::getParameters ( )
inherited
Return values
array<non-empty-string,mixed>

◆ getPeriod()

OTPHP\TOTP::getPeriod ( )

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

Implements OTPHP\TOTPInterface.

◆ getProvisioningUri()

OTPHP\TOTP::getProvisioningUri ( )

Get the provisioning URI.

Return values
non-empty-string

Implements OTPHP\OTPInterface.

◆ getQrCodeUri()

OTPHP\OTP::getQrCodeUri ( string $uri,
string $placeholder )
inherited

Get the provisioning URI.

Parameters
non-empty-string$uriThe Uri of the QRCode generator with all parameters. This Uri MUST contain a placeholder that will be replaced by the method.
non-empty-string$placeholderthe placeholder to be replaced in the QR Code generator URI

Implements OTPHP\OTPInterface.

◆ getSecret()

OTPHP\OTPInterface::getSecret ( )
inherited
Return values
non-empty-stringThe secret of the OTP

◆ hasParameter()

OTPHP\OTPInterface::hasParameter ( string $parameter)
inherited
Parameters
non-empty-string$parameter

◆ isIssuerIncludedAsParameter()

OTPHP\OTPInterface::isIssuerIncludedAsParameter ( )
inherited
Return values
boolIf true, the issuer will be added as a parameter in the provisioning URI

◆ now()

OTPHP\TOTP::now ( )

Return the TOTP at the current time.

Return values
non-empty-string

Implements OTPHP\TOTPInterface.

◆ setDigest()

OTPHP\OTPInterface::setDigest ( string $digest)
inherited
Parameters
non-empty-string$digest

◆ setEpoch()

OTPHP\TOTP::setEpoch ( int $epoch)

Implements OTPHP\TOTPInterface.

◆ setIssuer()

OTPHP\OTPInterface::setIssuer ( string $issuer)
inherited
Parameters
non-empty-string$issuer

◆ setLabel()

OTPHP\OTPInterface::setLabel ( string $label)
inherited
Parameters
non-empty-string$labelThe label of the OTP

◆ setParameter()

OTPHP\OTPInterface::setParameter ( string $parameter,
mixed $value )
inherited
Parameters
non-empty-string$parameter

◆ setPeriod()

OTPHP\TOTP::setPeriod ( int $period)

Implements OTPHP\TOTPInterface.

◆ setSecret()

OTPHP\OTPInterface::setSecret ( string $secret)
inherited
Parameters
non-empty-string$secret

◆ verify()

OTPHP\TOTP::verify ( string $otp,
null|int $timestamp = null,
null|int $leeway = null )

If no timestamp is provided, the OTP is verified at the actual timestamp.

When used, the leeway parameter will allow time drift. The passed value is in seconds.

Parameters
0 | positive-int$timestamp
null | 0 | positive-int$leeway

Implements OTPHP\OTPInterface.


The documentation for this class was generated from the following file: