Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/auth/db/ -> auth.php (source)

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

Authentication Plugin: External Database Authentication Checks against an external database.

Author: Martin Dougiamas
License: http://www.gnu.org/copyleft/gpl.html GNU Public License
File Size: 790 lines (30 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: auth_plugin_db  - X-Ref

External database authentication plugin.

__construct()   X-Ref
Constructor.


user_login($username, $password)   X-Ref
Returns true if the username and password work and false if they are
wrong or don't exist.

param: string $username The username
param: string $password The password
return: bool Authentication success or failure.

db_init()   X-Ref
Connect to external database.

return: ADOConnection

db_attributes()   X-Ref
Returns user attribute mappings between moodle and the external database.

return: array

get_userinfo($username)   X-Ref
Reads any other information for a user from external database,
then returns it in an array.

param: string $username
return: array

user_update_password($user, $newpassword)   X-Ref
Change a user's password.

param: stdClass  $user      User table object
param: string  $newpassword Plaintext password
return: bool                 True on success

sync_users(progress_trace $trace, $do_updates=false)   X-Ref
Synchronizes user from external db to moodle user table.

Sync should be done by using idnumber attribute, not username.
You need to pass firstsync parameter to function to fill in
idnumbers if they don't exists in moodle user table.

Syncing users removes (disables) users that don't exists anymore in external db.
Creates new users and updates coursecreator status of users.

This implementation is simpler but less scalable than the one found in the LDAP module.

param: progress_trace $trace
param: bool $do_updates  Optional: set to true to force an update of existing accounts
return: int 0 means success, 1 means failure

user_exists($username)   X-Ref
No description

get_userlist()   X-Ref
No description

get_userinfo_asobj($username)   X-Ref
Reads user information from DB and return it in an object.

param: string $username username
return: array

user_update($olduser, $newuser)   X-Ref
Called when the user record is updated.
Modifies user in external database. It takes olduser (before changes) and newuser (after changes)
compares information saved modified information to external db.

param: stdClass $olduser     Userobject before modifications
param: stdClass $newuser     Userobject new modified userobject
return: boolean result

prevent_local_passwords()   X-Ref
No description

is_internal()   X-Ref
Returns true if this authentication plugin is "internal".

Internal plugins use password hashes from Moodle user table for authentication.

return: bool

is_configured()   X-Ref
Returns false if this plugin is enabled but not configured.

return: bool

is_synchronised_with_external()   X-Ref
Indicates if moodle should automatically update internal user
records with data from external sources using the information
from auth_plugin_base::get_userinfo().

return: bool true means automatically copy data from ext to user table

can_change_password()   X-Ref
Returns true if this authentication plugin can change the user's
password.

return: bool

change_password_url()   X-Ref
Returns the URL for changing the user's pw, or empty if the default can
be used.

return: moodle_url

can_reset_password()   X-Ref
Returns true if plugin allows resetting of internal password.

return: bool

ext_addslashes($text)   X-Ref
Add slashes, we can not use placeholders or system functions.

param: string $text
return: string

test_settings()   X-Ref
Test if settings are ok, print info to output.


clean_data($user)   X-Ref
Clean the user data that comes from an external database.

param: array $user the user data to be validated against properties definition.
return: stdClass $user the cleaned user data.