Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
factor_totp\factor Class Reference
Inheritance diagram for factor_totp\factor:
tool_mfa\local\factor\object_factor_base tool_mfa\local\factor\object_factor

Public Member Functions

 check_combination (array $combination)
 Checks whether the factor combination is valid based on factor behaviour.
 
 create_event_after_factor_setup (object $user)
 Creates an event when user successfully setup a factor.
 
 delete_factor_for_user (stdClass $user)
 Deletes all instances of factor for a user.
 
 generate_qrcode (string $secret)
 Generates HTML sting with QR code for given secret key.
 
 generate_secret_code ()
 Generates cryptographically secure pseudo-random 16-digit secret code.
 
 generate_totp_uri (string $secret)
 Generates TOTP URI for given secret key.
 
 get_active_user_factors (stdClass $user)
 Returns an array of active user factor records.
 
 get_all_user_factors ($user)
 TOTP Factor implementation.
 
 get_all_user_factors (stdClass $user)
 Returns an array of all user factors of given type (both active and revoked).
 
 get_display_name ()
 Returns factor name from language string.
 
 get_icon ()
 Get the icon associated with this factor.
 
 get_info ()
 Returns factor help from language string.
 
 get_label (int $factorid)
 Function to retrieve the label for a factorid.
 
 get_lastverified (int $factorid)
 Gets lastverified timestamp.
 
 get_login_desc ()
 Get the login description associated with this factor.
 
 get_manage_info (int $factorid)
 Returns factor help from language string when there is factor management available.
 
 get_manage_string ()
 Gets the string for manage button on preferences page.
 
 get_no_redirect_urls ()
 Function to get urls that should not be redirected from.
 
 get_remaining_attempts ()
 Return the number of remaining attempts at this factor.
 
 get_setup_string ()
 TOTP Factor implementation.
 
 get_state ()
 TOTP state.
 
 get_summary_condition ()
 Returns condition for passing factor.
 
 get_weight ()
 Returns configured factor weight.
 
 global_definition (\MoodleQuickForm $mform)
 Hook point for global auth form action hooks.
 
 global_definition_after_data (\MoodleQuickForm $mform)
 Hook point for global auth form action hooks.
 
 global_submit (object $data)
 Hook point for global auth form action hooks.
 
 global_validation (array $data, array $files)
 Hook point for global auth form action hooks.
 
 has_input ()
 Returns true if a factor requires input from the user to verify.
 
 has_replace ()
 TOTP Factor implementation.
 
 has_revoke ()
 TOTP Factor implementation.
 
 has_setup ()
 TOTP Factor implementation.
 
 increment_lock_counter ()
 Increments the lock counter for a factor.
 
 is_enabled ()
 Returns true if factor is enabled, otherwise false.
 
 is_lockable ()
 Returns true if a factor is able to be locked if it fails.
 
 load_locked_state ()
 This loads the locked state from the DB Base class implementation.
 
 login_form_definition (\MoodleQuickForm $mform)
 TOTP Factor implementation.
 
 login_form_definition_after_data (\MoodleQuickForm $mform)
 Defines login form definition page after form data has been set.
 
 login_form_validation (array $data)
 TOTP Factor implementation.
 
 possible_states (stdClass $user)
 TOTP Factor implementation.
 
 post_pass_state ()
 TOTP Factor implementation.
 
 process_cancel_action ()
 Process a cancel input from a user.
 
 replace_user_factor (stdClass $data, int $id)
 TOTP Factor implementation with replacement of existing factor.
 
 revoke_user_factor (?int $factorid=null)
 Marks factor record as revoked.
 
 set_state (string $state)
 Sets the state of the factor into the session.
 
 setup_factor_form_definition (\MoodleQuickForm $mform)
 TOTP Factor implementation.
 
 setup_factor_form_definition_after_data (\MoodleQuickForm $mform)
 TOTP Factor implementation.
 
 setup_factor_form_is_cancelled (int $factorid)
 Setups in given factor when the form is cancelled.
 
 setup_factor_form_submit_button_string ()
 Setup submit button string in given factor.
 
 setup_factor_form_validation (array $data)
 TOTP Factor implementation.
 
 setup_user_factor (stdClass $data)
 TOTP Factor implementation.
 
 show_setup_buttons ()
 TOTP Factor implementation.
 
 update_lastverified (?int $factorid=null)
 When validation code is correct - update lastverified field for given factor.
 
 validate_code (string $code, int $window, TOTP $totp, stdClass $factor)
 Checks the code for reuse, clock skew, and validity.
 

Public Attributes

string $name
 Factor name.
 
string const TOTP_FUTURE = 'future'
 
string const TOTP_INVALID = 'invalid'
 
string const TOTP_OLD = 'old'
 
string const TOTP_USED = 'used'
 
string const TOTP_VALID = 'valid'
 

Protected Attributes

string $icon = 'fa-mobile-screen'
 Factor icon.
 
tool_mfa local secret_manager $secretmanager
 Secret manager.
 

Member Function Documentation

◆ check_combination()

tool_mfa\local\factor\object_factor_base::check_combination ( array $combination)
inherited

Checks whether the factor combination is valid based on factor behaviour.

E.g. a combination with nosetup and another factor is not valid, as you cannot pass nosetup with another factor.

Parameters
array$combinationarray of factors that make up the combination
Return values
bool

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_grace\factor, and factor_nosetup\factor.

◆ create_event_after_factor_setup()

tool_mfa\local\factor\object_factor_base::create_event_after_factor_setup ( object $user)
inherited

Creates an event when user successfully setup a factor.

Parameters
object$user
Return values
void

◆ delete_factor_for_user()

tool_mfa\local\factor\object_factor_base::delete_factor_for_user ( stdClass $user)
inherited

Deletes all instances of factor for a user.

Parameters
stdClass$userthe user to delete for.
Return values
void

Implements tool_mfa\local\factor\object_factor.

◆ generate_qrcode()

factor_totp\factor::generate_qrcode ( string $secret)

Generates HTML sting with QR code for given secret key.

Parameters
string$secret
Return values
string

◆ generate_secret_code()

factor_totp\factor::generate_secret_code ( )

Generates cryptographically secure pseudo-random 16-digit secret code.

Return values
string

◆ generate_totp_uri()

factor_totp\factor::generate_totp_uri ( string $secret)

Generates TOTP URI for given secret key.

Uses site name, hostname and user name to make GA account look like: "Sitename hostname (username)".

Parameters
string$secret
Return values
string

◆ get_active_user_factors()

tool_mfa\local\factor\object_factor_base::get_active_user_factors ( stdClass $user)
inherited

Returns an array of active user factor records.

Filters get_all_user_factors() output.

Parameters
stdClass$userobject to check against.
Return values
array

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_grace\factor.

◆ get_all_user_factors() [1/2]

factor_totp\factor::get_all_user_factors ( $user)

TOTP Factor implementation.

Parameters
stdClass$userthe user to check against.
Return values
array

◆ get_all_user_factors() [2/2]

tool_mfa\local\factor\object_factor_base::get_all_user_factors ( stdClass $user)
inherited

Returns an array of all user factors of given type (both active and revoked).

Dummy implementation. Should be overridden in child class.

Parameters
stdClass$userthe user to check against.
Return values
array

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_admin\factor, factor_auth\factor, factor_capability\factor, factor_cohort\factor, factor_email\factor, factor_grace\factor, factor_iprange\factor, factor_nosetup\factor, factor_role\factor, factor_sms\factor, factor_token\factor, and factor_webauthn\factor.

◆ get_display_name()

tool_mfa\local\factor\object_factor_base::get_display_name ( )
inherited

Returns factor name from language string.

Base class implementation.

Return values
string
Exceptions
coding_exception

Implements tool_mfa\local\factor\object_factor.

Reimplemented in tool_mfa\local\factor\fallback.

◆ get_icon()

tool_mfa\local\factor\object_factor_base::get_icon ( )
inherited

Get the icon associated with this factor.

Return values
stringthe icon name.

◆ get_info()

tool_mfa\local\factor\object_factor_base::get_info ( )
inherited

Returns factor help from language string.

Base class implementation.

Return values
string
Exceptions
coding_exception

Implements tool_mfa\local\factor\object_factor.

Reimplemented in tool_mfa\local\factor\fallback.

◆ get_label()

tool_mfa\local\factor\object_factor_base::get_label ( int $factorid)
inherited

Function to retrieve the label for a factorid.

Parameters
int$factorid
Return values
string|dml_exception

Implements tool_mfa\local\factor\object_factor.

◆ get_lastverified()

tool_mfa\local\factor\object_factor_base::get_lastverified ( int $factorid)
inherited

Gets lastverified timestamp.

Parameters
int$factorid
Return values
int|boolthe lastverified timestamp, or false if not found.

Implements tool_mfa\local\factor\object_factor.

◆ get_login_desc()

tool_mfa\local\factor\object_factor_base::get_login_desc ( )
inherited

Get the login description associated with this factor.

Override for factors that have a user input.

Return values
stringThe login option.

Reimplemented in factor_email\factor, and factor_sms\factor.

◆ get_manage_info()

tool_mfa\local\factor\object_factor_base::get_manage_info ( int $factorid)
inherited

Returns factor help from language string when there is factor management available.

Base class implementation.

Parameters
int$factoridThe factor we want manage info for.
Return values
string
Exceptions
coding_exception

◆ get_manage_string()

factor_totp\factor::get_manage_string ( )

Gets the string for manage button on preferences page.

Return values
string

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ get_no_redirect_urls()

tool_mfa\local\factor\object_factor_base::get_no_redirect_urls ( )
inherited

Function to get urls that should not be redirected from.

Return values
array

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_email\factor, and factor_grace\factor.

◆ get_remaining_attempts()

tool_mfa\local\factor\object_factor_base::get_remaining_attempts ( )
inherited

Return the number of remaining attempts at this factor.

Return values
intthe number of attempts at this factor remaining.

◆ get_setup_string()

factor_totp\factor::get_setup_string ( )

TOTP Factor implementation.

Gets the string for setup button on preferences page.

Return values
string

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ get_state()

factor_totp\factor::get_state ( )

TOTP state.

Returns the state of the factor from session information.Implementation for factors that require input. Should be overridden in child classes with no input.

Return values
mixed

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ get_summary_condition()

tool_mfa\local\factor\object_factor_base::get_summary_condition ( )
inherited

Returns condition for passing factor.

Implementation for basic conditions. Override for complex conditions such as auth type.

Return values
string

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_auth\factor, factor_cohort\factor, and factor_role\factor.

◆ get_weight()

tool_mfa\local\factor\object_factor_base::get_weight ( )
inherited

Returns configured factor weight.

Base class implementation.

Return values
int
Exceptions
dml_exception

Implements tool_mfa\local\factor\object_factor.

◆ global_definition()

tool_mfa\local\factor\object_factor_base::global_definition ( \MoodleQuickForm $mform)
inherited

Hook point for global auth form action hooks.

Parameters
MoodleQuickForm$mformForm to inject global elements into.
Return values
void

Implements tool_mfa\local\factor\object_factor.

◆ global_definition_after_data()

tool_mfa\local\factor\object_factor_base::global_definition_after_data ( \MoodleQuickForm $mform)
inherited

Hook point for global auth form action hooks.

Parameters
MoodleQuickForm$mformForm to inject global elements into.
Return values
void

Implements tool_mfa\local\factor\object_factor.

◆ global_submit()

tool_mfa\local\factor\object_factor_base::global_submit ( object $data)
inherited

Hook point for global auth form action hooks.

Parameters
object$dataData from the form.
Return values
void

Implements tool_mfa\local\factor\object_factor.

◆ global_validation()

tool_mfa\local\factor\object_factor_base::global_validation ( array $data,
array $files )
inherited

Hook point for global auth form action hooks.

Parameters
array$dataData from the form.
array$filesFiles form the form.
Return values
arrayof errors from validation.

Implements tool_mfa\local\factor\object_factor.

◆ has_input()

tool_mfa\local\factor\object_factor_base::has_input ( )
inherited

◆ has_replace()

factor_totp\factor::has_replace ( )

TOTP Factor implementation.

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ has_revoke()

factor_totp\factor::has_revoke ( )

TOTP Factor implementation.

Returns true if factor class has factor records that might be revoked.It means that user can revoke factor record from their profile.Override in child class if necessary.

Return values
bool

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ has_setup()

factor_totp\factor::has_setup ( )

TOTP Factor implementation.

Returns true if factor needs to be setup by user and has setup_form.Override in child class if necessary.

Return values
bool

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ increment_lock_counter()

tool_mfa\local\factor\object_factor_base::increment_lock_counter ( )
inherited

Increments the lock counter for a factor.

Return values
void

◆ is_enabled()

tool_mfa\local\factor\object_factor_base::is_enabled ( )
inherited

Returns true if factor is enabled, otherwise false.

Base class implementation.

Return values
bool
Exceptions
dml_exception

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_sms\factor.

◆ is_lockable()

tool_mfa\local\factor\object_factor_base::is_lockable ( )
inherited

Returns true if a factor is able to be locked if it fails.

Generally only input factors are lockable. Override in child class if necessary

Return values
bool

◆ load_locked_state()

tool_mfa\local\factor\object_factor_base::load_locked_state ( )
inherited

This loads the locked state from the DB Base class implementation.

Return values
void

◆ login_form_definition()

factor_totp\factor::login_form_definition ( \MoodleQuickForm $mform)

TOTP Factor implementation.

Parameters
MoodleQuickForm$mform
Return values
MoodleQuickForm\$mform

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ login_form_definition_after_data()

tool_mfa\local\factor\object_factor_base::login_form_definition_after_data ( \MoodleQuickForm $mform)
inherited

Defines login form definition page after form data has been set.

Dummy implementation. Should be overridden in child class.

Parameters
MoodleQuickForm$mform
Return values
MoodleQuickForm\$mform

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_email\factor, and factor_sms\factor.

◆ login_form_validation()

factor_totp\factor::login_form_validation ( array $data)

TOTP Factor implementation.

Parameters
array$data
Return values
array

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ possible_states()

factor_totp\factor::possible_states ( stdClass $user)

TOTP Factor implementation.

TOTP cannot return fail state.

Parameters
stdClass$user

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ post_pass_state()

factor_totp\factor::post_pass_state ( )

TOTP Factor implementation.

Empty override of parent.

Function for factor actions in the pass state.Override in child class if necessary.

Return values
void

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ process_cancel_action()

tool_mfa\local\factor\object_factor_base::process_cancel_action ( )
inherited

Process a cancel input from a user.

Return values
void

Implements tool_mfa\local\factor\object_factor.

◆ replace_user_factor()

factor_totp\factor::replace_user_factor ( stdClass $data,
int $id )

TOTP Factor implementation with replacement of existing factor.

Parameters
stdClass$dataThe new factor data.
int$idThe id of the factor to replace.
Return values
stdClass|nullthe factor record, or null.

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ revoke_user_factor()

tool_mfa\local\factor\object_factor_base::revoke_user_factor ( ?int $factorid = null)
inherited

Marks factor record as revoked.

If factorid is not provided, revoke all instances of factor.

Parameters
int | null$factorid
Return values
bool
Exceptions
coding_exception
dml_exception

Implements tool_mfa\local\factor\object_factor.

◆ set_state()

tool_mfa\local\factor\object_factor_base::set_state ( string $state)
inherited

Sets the state of the factor into the session.

Implementation for factors that require input. Should be overridden in child classes with no input.

Parameters
string$statethe state constant to set.
Return values
bool

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_auth\factor, factor_capability\factor, factor_cohort\factor, factor_grace\factor, factor_iprange\factor, factor_nosetup\factor, factor_role\factor, and tool_mfa\local\factor\fallback.

◆ setup_factor_form_definition()

factor_totp\factor::setup_factor_form_definition ( \MoodleQuickForm $mform)

TOTP Factor implementation.

Parameters
MoodleQuickForm$mform
Return values
MoodleQuickForm\$mform

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ setup_factor_form_definition_after_data()

factor_totp\factor::setup_factor_form_definition_after_data ( \MoodleQuickForm $mform)

TOTP Factor implementation.

Parameters
MoodleQuickForm$mform
Return values
MoodleQuickForm\$mform

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ setup_factor_form_is_cancelled()

tool_mfa\local\factor\object_factor_base::setup_factor_form_is_cancelled ( int $factorid)
inherited

Setups in given factor when the form is cancelled.

Dummy implementation. Should be overridden in child class.

Parameters
int$factorid
Return values
void

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_sms\factor.

◆ setup_factor_form_submit_button_string()

tool_mfa\local\factor\object_factor_base::setup_factor_form_submit_button_string ( )
inherited

Setup submit button string in given factor.

Dummy implementation. Should be overridden in child class.

Return values
string|null

Implements tool_mfa\local\factor\object_factor.

Reimplemented in factor_sms\factor.

◆ setup_factor_form_validation()

factor_totp\factor::setup_factor_form_validation ( array $data)

TOTP Factor implementation.

Parameters
array$data
Return values
array

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ setup_user_factor()

factor_totp\factor::setup_user_factor ( stdClass $data)

TOTP Factor implementation.

Parameters
stdClass$data
Return values
stdClass|nullthe factor record, or null.

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ show_setup_buttons()

factor_totp\factor::show_setup_buttons ( )

TOTP Factor implementation.

If has_setup returns true, decides if the setup buttons should be shown on the preferences page.

Return values
bool

Reimplemented from tool_mfa\local\factor\object_factor_base.

◆ update_lastverified()

tool_mfa\local\factor\object_factor_base::update_lastverified ( ?int $factorid = null)
inherited

When validation code is correct - update lastverified field for given factor.

If factor id is not provided, update all factor entries for user.

Parameters
int | null$factorid
Return values
bool|dml_exception
Exceptions
dml_exception

Implements tool_mfa\local\factor\object_factor.

◆ validate_code()

factor_totp\factor::validate_code ( string $code,
int $window,
TOTP $totp,
stdClass $factor )

Checks the code for reuse, clock skew, and validity.

Parameters
string$codethe code to check.
int$windowthe window to check validity for.
TOTP$totpthe totp object to check against.
stdClass$factorthe factor with information required.
Return values
stringconstant with verification state.

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