Documentation

Users_Totp_Authmethod
in package

TOTP authentication method class.

Table of Contents

ALLOWED_USER_AUTHY_MODE  = ['TOTP_OFF', 'TOTP_OPTIONAL', 'TOTP_OBLIGATORY']
$authenticator  : Google2FA
$secret  : string
$userId  : int
__construct()  : mixed
Constructor.
createQrCodeForUser()  : path|string
Create QR code for user.
createSecret()  : string
Creating a secret code for TOTP.
getCode()  : string
2FA - get the current one time password.
getOtpAuthUrl()  : string
Generate TOTP code url.
isActive()  : bool
Determine whether 2FA is required.
mustInit()  : bool
Check if 2FA initiation is necessary.
verifyCode()  : bool
2FA - verification of the code from the user.
createQrCode()  : path|string
Create QR code.

Constants

ALLOWED_USER_AUTHY_MODE

public array<string|int, string> ALLOWED_USER_AUTHY_MODE = ['TOTP_OFF', 'TOTP_OPTIONAL', 'TOTP_OBLIGATORY']

User authentication mode possible values. TOTP_OFF - 2FA TOTP is checking off TOTP_OPTIONAL - It is defined by the user TOTP_OBLIGATORY - It is obligatory.

Properties

$authenticator

private Google2FA $authenticator

$secret

private string $secret
  • Secret code

$userId

private int $userId
  • User id

Methods

__construct()

Constructor.

public __construct(int $userId) : mixed
Parameters
$userId : int
  • Id of user
Return values
mixed

createQrCodeForUser()

Create QR code for user.

public createQrCodeForUser([string $type = 'PNG' ]) : path|string
Parameters
$type : string = 'PNG'
  • acceptable types [HTML, SVG, PNG]
Tags
throws
NotAllowedMethod
Return values
path|string

createSecret()

Creating a secret code for TOTP.

public createSecret() : string
Return values
string

getCode()

2FA - get the current one time password.

public getCode() : string
Return values
string

getOtpAuthUrl()

Generate TOTP code url.

public getOtpAuthUrl(string $secret, string $name[, string|null $issuer = null ]) : string
Parameters
$secret : string
  • REQUIRED: The secret parameter is an arbitrary key value encoded in Base32 according to RFC 3548. The padding specified in RFC 3548 section 2.2 is not required and should be omitted.
$name : string
  • The name is used to identify which account a key is associated with.
$issuer : string|null = null
  • The issuer parameter is a string value indicating the provider or service this account is associated with, URL-encoded according to RFC 3986.
Return values
string
  • Url

isActive()

Determine whether 2FA is required.

public static isActive([int|null $userId = null ]) : bool
Parameters
$userId : int|null = null
  • if null then getCurrentUserRealId
Return values
bool

mustInit()

Check if 2FA initiation is necessary.

public static mustInit([int|null $userId = null ]) : bool
Parameters
$userId : int|null = null
  • if null then getCurrentUserRealId
Return values
bool

verifyCode()

2FA - verification of the code from the user.

public verifyCode(string $secret, string $userCode) : bool
Parameters
$secret : string
$userCode : string
Return values
bool

createQrCode()

Create QR code.

private createQrCode(string $otpAuthUrl[, string $type = 'HTML' ]) : path|string
Parameters
$otpAuthUrl : string
$type : string = 'HTML'
  • acceptable types [HTML, SVG, PNG]
Tags
throws
NotAllowedMethod
Return values
path|string
  • HTML code

        

Search results