Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Class: object_factor_base  - X-Ref

MFA factor abstract class.

__construct($name)   X-Ref
Class constructor

param: string $name factor name

load_locked_state()   X-Ref
This loads the locked state from the DB
Base class implementation.

return: void

is_enabled()   X-Ref
Returns true if factor is enabled, otherwise false.

Base class implementation.

return: bool

get_weight()   X-Ref
Returns configured factor weight.

Base class implementation.

return: int

get_display_name()   X-Ref
Returns factor name from language string.

Base class implementation.

return: string

get_info()   X-Ref
Returns factor help from language string.

Base class implementation.

return: string

setup_factor_form_definition(\MoodleQuickForm $mform)   X-Ref
Defines setup_factor form definition page for particular factor.

Dummy implementation. Should be overridden in child class.

param: \MoodleQuickForm $mform
return: object $mform

setup_factor_form_definition_after_data(\MoodleQuickForm $mform)   X-Ref
Defines setup_factor form definition page after form data has been set.

Dummy implementation. Should be overridden in child class.

param: \MoodleQuickForm $mform
return: object $mform

setup_factor_form_validation(array $data)   X-Ref
Implements setup_factor form validation for particular factor.
Returns an array of errors, where array key = field id and array value = error text.

Dummy implementation. Should be overridden in child class.

param: array $data
return: array

setup_user_factor(stdClass $data)   X-Ref
Setups given factor and adds it to user's active factors list.
Returns true if factor has been successfully added, otherwise false.

Dummy implementation. Should be overridden in child class.

param: stdClass $data
return: stdClass|null the record if created, or null.

get_all_user_factors(stdClass $user)   X-Ref
Returns an array of all user factors of given type (both active and revoked).

Dummy implementation. Should be overridden in child class.

param: stdClass $user the user to check against.
return: array

get_active_user_factors(stdClass $user)   X-Ref
Returns an array of active user factor records.
Filters get_all_user_factors() output.

param: stdClass $user object to check against.
return: array

login_form_definition(\MoodleQuickForm $mform)   X-Ref
Defines login form definition page for particular factor.

Dummy implementation. Should be overridden in child class.

param: \MoodleQuickForm $mform
return: object $mform

login_form_definition_after_data(\MoodleQuickForm $mform)   X-Ref
Defines login form definition page after form data has been set.

Dummy implementation. Should be overridden in child class.

param: \MoodleQuickForm $mform
return: object $mform

login_form_validation(array $data)   X-Ref
Implements login form validation for particular factor.
Returns an array of errors, where array key = field id and array value = error text.

Dummy implementation. Should be overridden in child class.

param: array $data
return: array

has_revoke()   X-Ref
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: bool

revoke_user_factor(?int $factorid = null)   X-Ref
Marks factor record as revoked.
If factorid is not provided, revoke all instances of factor.

param: int|null $factorid
return: bool

update_lastverified(?int $factorid = null)   X-Ref
When validation code is correct - update lastverified field for given factor.
If factor id is not provided, update all factor entries for user.

param: int|null $factorid
return: bool|\dml_exception

get_lastverified(int $factorid)   X-Ref
Gets lastverified timestamp.

param: int $factorid
return: int|bool the lastverified timestamp, or false if not found.

has_setup()   X-Ref
Returns true if factor needs to be setup by user and has setup_form.
Override in child class if necessary.

return: bool

show_setup_buttons()   X-Ref
If has_setup returns true, decides if the setup buttons should be shown on the preferences page.

return: bool

has_input()   X-Ref
Returns true if a factor requires input from the user to verify.

Override in child class if necessary

return: bool

is_lockable()   X-Ref
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: bool

get_state()   X-Ref
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: mixed

set_state(string $state)   X-Ref
Sets the state of the factor into the session.

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

param: string $state the state constant to set.
return: bool

create_event_after_factor_setup(object $user)   X-Ref
Creates an event when user successfully setup a factor

param: object $user
return: void

post_pass_state()   X-Ref
Function for factor actions in the pass state.
Override in child class if necessary.

return: void

get_label(int $factorid)   X-Ref
Function to retrieve the label for a factorid.

param: int $factorid
return: string|\dml_exception

get_no_redirect_urls()   X-Ref
Function to get urls that should not be redirected from.

return: array

possible_states(stdClass $user)   X-Ref
Function to get possible states for a user from factor.
Implementation where state is based on deterministic user data.
This should be overridden in factors where state is non-deterministic.
E.g. IP changes based on whether a user is using a VPN.

param: stdClass $user
return: array

get_summary_condition()   X-Ref
Returns condition for passing factor.
Implementation for basic conditions.
Override for complex conditions such as auth type.

return: string

check_combination(array $combination)   X-Ref
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.

param: array $combination array of factors that make up the combination
return: bool

get_setup_string()   X-Ref
Gets the string for setup button on preferences page.

return: string

delete_factor_for_user(stdClass $user)   X-Ref
Deletes all instances of factor for a user.

param: stdClass $user the user to delete for.
return: void

increment_lock_counter()   X-Ref
Increments the lock counter for a factor.

return: void

get_remaining_attempts()   X-Ref
Return the number of remaining attempts at this factor.

return: int the number of attempts at this factor remaining.

process_cancel_action()   X-Ref
Process a cancel input from a user.

return: void

global_definition(\MoodleQuickForm $mform)   X-Ref
Hook point for global auth form action hooks.

param: \MoodleQuickForm $mform Form to inject global elements into.
return: void

global_definition_after_data(\MoodleQuickForm $mform)   X-Ref
Hook point for global auth form action hooks.

param: \MoodleQuickForm $mform Form to inject global elements into.
return: void

global_validation(array $data, array $files)   X-Ref
Hook point for global auth form action hooks.

param: array $data Data from the form.
param: array $files Files form the form.
return: array of errors from validation.

global_submit(object $data)   X-Ref
Hook point for global auth form action hooks.

param: object $data Data from the form.
return: void

get_icon()   X-Ref
Get the icon associated with this factor.

return: string the icon name.

get_login_desc()   X-Ref
Get the login description associated with this factor.
Override for factors that have a user input.

return: string The login option.