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: factor  - X-Ref

TOTP factor class.

generate_totp_uri(string $secret)   X-Ref
Generates TOTP URI for given secret key.
Uses site name, hostname and user name to make GA account look like:
"Sitename hostname (username)".

param: string $secret
return: string

generate_qrcode(string $secret)   X-Ref
Generates HTML sting with QR code for given secret key.

param: string $secret
return: string

get_state()   X-Ref
TOTP state

{@inheritDoc}

setup_factor_form_definition(\MoodleQuickForm $mform)   X-Ref
TOTP Factor implementation.

param: \MoodleQuickForm $mform
return: \MoodleQuickForm $mform

setup_factor_form_definition_after_data(\MoodleQuickForm $mform)   X-Ref
TOTP Factor implementation.

param: \MoodleQuickForm $mform
return: \MoodleQuickForm $mform

setup_factor_form_validation(array $data)   X-Ref
TOTP Factor implementation.

param: array $data
return: array

login_form_definition(\MoodleQuickForm $mform)   X-Ref
TOTP Factor implementation.

param: \MoodleQuickForm $mform
return: \MoodleQuickForm $mform

login_form_validation(array $data)   X-Ref
TOTP Factor implementation.

param: array $data
return: array

validate_code(string $code, int $window, TOTP $totp, stdClass $factor)   X-Ref
Checks the code for reuse, clock skew, and validity.

param: string $code the code to check.
param: int $window the window to check validity for.
param: TOTP $totp the totp object to check against.
param: stdClass $factor the factor with information required.
return: string constant with verification state.

generate_secret_code()   X-Ref
Generates cryptographically secure pseudo-random 16-digit secret code.

return: string

setup_user_factor(stdClass $data)   X-Ref
TOTP Factor implementation.

param: stdClass $data
return: stdClass the factor record, or null.

get_all_user_factors($user)   X-Ref
TOTP Factor implementation.

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

has_revoke()   X-Ref
TOTP Factor implementation.

{@inheritDoc}

has_setup()   X-Ref
TOTP Factor implementation.

{@inheritDoc}

show_setup_buttons()   X-Ref
TOTP Factor implementation

{@inheritDoc}

post_pass_state()   X-Ref
TOTP Factor implementation.
Empty override of parent.

{@inheritDoc}

possible_states(stdClass $user)   X-Ref
TOTP Factor implementation.
TOTP cannot return fail state.

param: stdClass $user

get_setup_string()   X-Ref
TOTP Factor implementation.

{@inheritDoc}