<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rrf5000</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/dev/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rrf5000"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/Special:Contributions/Rrf5000"/>
	<updated>2026-06-24T08:10:21Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:Developer_FAQ&amp;diff=45276</id>
		<title>Talk:Developer FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:Developer_FAQ&amp;diff=45276"/>
		<updated>2014-06-10T04:37:34Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: Request to fix broken links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The link &amp;quot;the documentation for datalib.php&amp;quot; appears to be broken. I believe that it should link to http://phpdocs.moodle.org/moodlecore/_lib---datalib.php.html instead of http://moodle.sourceforge.net/dhawes-phpdoc/moodlecore/_lib_datalib_php.html I&#039;m not sure though because the file is empty. Hopefully someone else knows now to fix this.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Echoing the earlier comment from 2007, the links to documentation on [[Developer_FAQ#How_do_I_insert.2Fretrieve_records_in_the_database.2C_without_creating_my_own_database_connections.3F|inserting and retrieving records in the database]] (datalib.php and dmllib.php) are broken.  Can anyone in the know correct the links?&lt;br /&gt;
--[[User:Ryan Foster|Ryan Foster]] ([[User talk:Ryan Foster|talk]]) 12:37, 10 June 2014 (WST)&lt;br /&gt;
&lt;br /&gt;
===Is there any information on creating a new module or plugin?===&lt;br /&gt;
This section contains a link to the &#039;Moodle 1.9 Extension Development&#039; book by Jonathan Moore and Michael Churchward. Is this book still relevant to Moodle 2 or does Moodle 2 make it out-of-date? In other words, can you use it to develop modules or plugins for Moodle 2, considering that Moodle 2 is such a big upgrade and so much of the Moodle 2 core code has changed significantly?&lt;br /&gt;
--[[User:Luis de Vasconcelos|Luis de Vasconcelos]] 11:19, 5 October 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
: In terms of whether someone is able to write code for Moodle 2.0,  we can divide people into various levels:&lt;br /&gt;
&lt;br /&gt;
:# People who cannot program in any computer language.&lt;br /&gt;
:# People who can program in at least one computer language.&lt;br /&gt;
:# People who can program in PHP&lt;br /&gt;
:# People who can write code for at least one version of Moodle.&lt;br /&gt;
:# People who can write code for Moodle 2.0.&lt;br /&gt;
&lt;br /&gt;
: I think that the gaps between each level in that hierarchy get smaller with each step you take. In the Moodle 1.9 world, this book was designed to take you from Level 3 to the old equivalent of level 5. With Moodle 2.0, it only takes you from Level 3 to Level 4, but that is significantly more than half way.&lt;br /&gt;
&lt;br /&gt;
: If you know nothing about Moodle development, the fastest way to get started is probably to read the book, and then tread the tutorials here about converting Moodle 1.9 code to Moodle 2.0.&lt;br /&gt;
&lt;br /&gt;
: So, the book is still useful. It would be excellent if (when) the book is updated to Moodle 2.0, but I don&#039;t think anyone is working on that yet.--[[User:Tim Hunt|Tim Hunt]] 18:53, 5 October 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:version.php&amp;diff=43740</id>
		<title>Talk:version.php</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:version.php&amp;diff=43740"/>
		<updated>2014-02-10T09:08:47Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* Version string and dependencies */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Anthony, I reverted your changes. They contradict [[Coding_style#Files]].--[[User:Tim Hunt|Tim Hunt]] 16:15, 29 March 2013 (WST)&lt;br /&gt;
&lt;br /&gt;
== Cron ==&lt;br /&gt;
&lt;br /&gt;
To me this seems wrong:&lt;br /&gt;
&lt;br /&gt;
&amp;gt; $plugin-&amp;gt;cron = 0;&lt;br /&gt;
&amp;gt; Optional - time interval (in seconds) between calls to the plugin&#039;s &#039;cron&#039; function; set to 0 to disable the cron function calls. &lt;br /&gt;
&lt;br /&gt;
I&#039;ve just noticed a plugin with cron = 0 running after I added a lib.php cron function there - the idea was to develop first then enable the cron, but logs show it runs every time system cron runs. Moodle 2.3.8 but I cannot find if this is a bug or just wrong documentation.&lt;br /&gt;
Anyone know which it should be? --[[User:Jason Robinson|Jason Robinson]] ([[User talk:Jason Robinson|talk]]) 17:09, 21 November 2013 (WST)&lt;br /&gt;
&lt;br /&gt;
== Version string and dependencies ==&lt;br /&gt;
&lt;br /&gt;
For the version string (&amp;quot;$plugin-&amp;gt;version&amp;quot;), what exactly is the purpose of the &amp;quot;xx&amp;quot; part of the string?  Is it meant for if there are multiple releases on a single day (because the author had to fix something urgently that day)?  Or is it meant for if there are multiple minor revisions over time based on a major release?&lt;br /&gt;
&lt;br /&gt;
Is &amp;quot;ANY_VERSION&amp;quot; actually a constant in Moodle for dependency checking?  This wasn&#039;t immediately clear from this page.&lt;br /&gt;
&lt;br /&gt;
Is there a method for setting a maximum version of a dependency?&lt;br /&gt;
&lt;br /&gt;
--[[User:Ryan Foster|Ryan Foster]] ([[User talk:Ryan Foster|talk]]) 17:08, 10 February 2014 (WST)&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=43430</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=43430"/>
		<updated>2013-12-19T20:09:05Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* File structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_plugins&amp;lt;/tt&amp;gt; table in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_internal()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin is &amp;quot;internal&amp;quot;.  Internal plugins use password hashes from Moodle user table for authentication.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.  This function automatically returns the opposite boolean of what is_internal() returns.  Returning true means MD5 password hashes will be stored in the user table.  Returning false means flag &#039;not_cached&#039; will be stored there instead.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_synchronised_with_external()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if moodle should automatically update internal user records with data from external sources using the information from get_userinfo() method.  This function automatically returns the opposite boolean of what is_internal() returns.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_signup()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_be_manually_set()&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
This function was introduced in the base class and returns false by default. If overriden by an authentication plugin to return true, the authentication plugin will be able to be manually set for users. For example, when bulk uploading users you will be able to select it as the authentication method they use.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:Authentication_plugins&amp;diff=42384</id>
		<title>Talk:Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:Authentication_plugins&amp;diff=42384"/>
		<updated>2013-09-23T20:01:40Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* prevent_local_passwords() documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To make the title and description translations of the plugin work, you must also create the class constructor.&lt;br /&gt;
&lt;br /&gt;
== prevent_local_passwords() documentation ==&lt;br /&gt;
&lt;br /&gt;
The current documentation states:&lt;br /&gt;
&lt;br /&gt;
:: Indicates if password hashes should be stored in local moodle database.&lt;br /&gt;
&lt;br /&gt;
The code in auth/none has no comments regarding this method.  Am I to assume that using &amp;quot;return false&amp;quot; allows password hashes to be stored in Moodle&#039;s database and &amp;quot;return true&amp;quot; &#039;&#039;prevents&#039;&#039; password hashes from being stored in Moodle&#039;s database?&lt;br /&gt;
&lt;br /&gt;
--[[User:Ryan Foster|Ryan Foster]] ([[User talk:Ryan Foster|talk]]) 04:21, 18 September 2013 (WST)&lt;br /&gt;
&lt;br /&gt;
: I found that there were comments in lib/authlib.php.&lt;br /&gt;
&lt;br /&gt;
: --[[User:Ryan Foster|Ryan Foster]] ([[User talk:Ryan Foster|talk]]) 04:01, 24 September 2013 (WST)&lt;br /&gt;
&lt;br /&gt;
== Overriding functions ==&lt;br /&gt;
&lt;br /&gt;
It seems there is some ambiguity about which functions should be overridden.  For example, I&#039;d imagine that get_title() and get_description() are not meant to be overridden, but there appears to be nothing stopping a developer from doing so.  Should this be marked here in the docs, commented in the code, or disallowed by making such functions &amp;quot;final&amp;quot;?&lt;br /&gt;
&lt;br /&gt;
--[[User:Ryan Foster|Ryan Foster]] ([[User talk:Ryan Foster|talk]]) 06:50, 21 September 2013 (WST)&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:Authentication_plugins&amp;diff=42360</id>
		<title>Talk:Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:Authentication_plugins&amp;diff=42360"/>
		<updated>2013-09-20T22:50:16Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* Overriding functions */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To make the title and description translations of the plugin work, you must also create the class constructor.&lt;br /&gt;
&lt;br /&gt;
== prevent_local_passwords() documentation ==&lt;br /&gt;
&lt;br /&gt;
The current documentation states:&lt;br /&gt;
&lt;br /&gt;
:: Indicates if password hashes should be stored in local moodle database.&lt;br /&gt;
&lt;br /&gt;
The code in auth/none has no comments regarding this method.  Am I to assume that using &amp;quot;return false&amp;quot; allows password hashes to be stored in Moodle&#039;s database and &amp;quot;return true&amp;quot; &#039;&#039;prevents&#039;&#039; password hashes from being stored in Moodle&#039;s database?&lt;br /&gt;
&lt;br /&gt;
--[[User:Ryan Foster|Ryan Foster]] ([[User talk:Ryan Foster|talk]]) 04:21, 18 September 2013 (WST)&lt;br /&gt;
&lt;br /&gt;
== Overriding functions ==&lt;br /&gt;
&lt;br /&gt;
It seems there is some ambiguity about which functions should be overridden.  For example, I&#039;d imagine that get_title() and get_description() are not meant to be overridden, but there appears to be nothing stopping a developer from doing so.  Should this be marked here in the docs, commented in the code, or disallowed by making such functions &amp;quot;final&amp;quot;?&lt;br /&gt;
&lt;br /&gt;
--[[User:Ryan Foster|Ryan Foster]] ([[User talk:Ryan Foster|talk]]) 06:50, 21 September 2013 (WST)&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42359</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42359"/>
		<updated>2013-09-20T22:32:02Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* can_confirm() */  Adding formatted information about default return value.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_internal()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin is &amp;quot;internal&amp;quot;.  Internal plugins use password hashes from Moodle user table for authentication.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.  This function automatically returns the opposite boolean of what is_internal() returns.  Returning true means MD5 password hashes will be stored in the user table.  Returning false means flag &#039;not_cached&#039; will be stored there instead.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_synchronised_with_external()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if moodle should automatically update internal user records with data from external sources using the information from get_userinfo() method.  This function automatically returns the opposite boolean of what is_internal() returns.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_signup()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42358</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42358"/>
		<updated>2013-09-20T22:30:22Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* Interfacing to API&amp;#039;s */  Adding can_signup() with formatted information on default return values.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_internal()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin is &amp;quot;internal&amp;quot;.  Internal plugins use password hashes from Moodle user table for authentication.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.  This function automatically returns the opposite boolean of what is_internal() returns.  Returning true means MD5 password hashes will be stored in the user table.  Returning false means flag &#039;not_cached&#039; will be stored there instead.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_synchronised_with_external()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if moodle should automatically update internal user records with data from external sources using the information from get_userinfo() method.  This function automatically returns the opposite boolean of what is_internal() returns.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_signup()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42357</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42357"/>
		<updated>2013-09-20T22:28:26Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* can_reset_password() */  Adding formatted information about default return value.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_internal()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin is &amp;quot;internal&amp;quot;.  Internal plugins use password hashes from Moodle user table for authentication.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.  This function automatically returns the opposite boolean of what is_internal() returns.  Returning true means MD5 password hashes will be stored in the user table.  Returning false means flag &#039;not_cached&#039; will be stored there instead.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_synchronised_with_external()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if moodle should automatically update internal user records with data from external sources using the information from get_userinfo() method.  This function automatically returns the opposite boolean of what is_internal() returns.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42356</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42356"/>
		<updated>2013-09-20T22:20:04Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* prevent_local_passwords() */  Adding formatted information on default return values.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_internal()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin is &amp;quot;internal&amp;quot;.  Internal plugins use password hashes from Moodle user table for authentication.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.  This function automatically returns the opposite boolean of what is_internal() returns.  Returning true means MD5 password hashes will be stored in the user table.  Returning false means flag &#039;not_cached&#039; will be stored there instead.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_synchronised_with_external()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if moodle should automatically update internal user records with data from external sources using the information from get_userinfo() method.  This function automatically returns the opposite boolean of what is_internal() returns.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42355</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42355"/>
		<updated>2013-09-20T22:14:24Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* Interfacing to API&amp;#039;s */  Adding is_synchronised_with_external() with formatted information on default return values.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_internal()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin is &amp;quot;internal&amp;quot;.  Internal plugins use password hashes from Moodle user table for authentication.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_synchronised_with_external()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if moodle should automatically update internal user records with data from external sources using the information from get_userinfo() method.  This function automatically returns the opposite boolean of what is_internal() returns.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : !$this-&amp;gt;is_internal()&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42354</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42354"/>
		<updated>2013-09-20T22:05:32Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* Interfacing to API&amp;#039;s */  Adding is_internal() with formatted information on default return values.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;is_internal()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin is &amp;quot;internal&amp;quot;.  Internal plugins use password hashes from Moodle user table for authentication.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42353</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42353"/>
		<updated>2013-09-20T22:02:36Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* can_edit_profile() */  Adding formatted information about default return value.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : true&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42352</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42352"/>
		<updated>2013-09-20T21:55:55Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* can_change_password() */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; &#039;&#039;&#039;Return type&#039;&#039;&#039; : boolean&lt;br /&gt;
; &#039;&#039;&#039;Default return value&#039;&#039;&#039; : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42351</id>
		<title>Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Authentication_plugins&amp;diff=42351"/>
		<updated>2013-09-20T21:52:05Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* can_change_password() */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
This page first gives an &#039;&#039;&#039;overview&#039;&#039;&#039; of the &#039;&#039;authentication process&#039;&#039; and then explains how &#039;&#039;authentication modules&#039;&#039; can be &#039;&#039;&#039;created&#039;&#039;&#039; using hooks to take over from the native authentication in Moodle.&lt;br /&gt;
=== Overview of Moodle authentication process ===&lt;br /&gt;
[[File:1.9.11_login_element.png|203px||thumb|right|The login UI element in Moodle 1.9]]The authentication use case in Moodle starts when a user clicks on the Login link in the UI. Then the following happens (skipping some minor details and rarer scenarios):&lt;br /&gt;
&lt;br /&gt;
# The default login page (&amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt;) is displayed. OR, if a system administrator has set the Alternate Login URL on the &amp;quot;Manage authentication&amp;quot; page, that URL will be displayed.&lt;br /&gt;
# A user enters their credentials and submits the form.&lt;br /&gt;
# The handler code in &amp;lt;tt&amp;gt;/login/index.php&amp;lt;/tt&amp;gt; runs:&lt;br /&gt;
## Gets a list of enabled authentication plugins.&lt;br /&gt;
## Runs &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt; for each plugin, in case any of them needs to intercept the login request.&lt;br /&gt;
## Checks to make sure that the username meets Moodle&#039;s criteria (alphanumeric, with periods and hyphens allowed).&lt;br /&gt;
## Calls &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt; in &amp;lt;tt&amp;gt;/lib/moodlelib.php&amp;lt;/tt&amp;gt;, which returns a &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; object. (Details of this code follow this main outline.)&lt;br /&gt;
## Determines whether authentication was successful (by checking whether &amp;lt;code&amp;gt;$user&amp;lt;/code&amp;gt; is a valid object) and, if not, sends them back to the login page with an error message. Otherwise, it figures out where to send the user based on their original page request, whether their password is expired, etc., and redirects them there.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
Authentication plugins exist from 1.9&lt;br /&gt;
==Example==&lt;br /&gt;
[http://moodle.org/plugins/view.php?plugin=auth_googleoauth2 Google / Facebook / Messenger Oauth2 Authentication plugin]&lt;br /&gt;
&lt;br /&gt;
==Template==&lt;br /&gt;
Please see Moodle &#039;&#039;&#039;none&#039;&#039;&#039; authentication plugin (auth/none), it&#039;s the perfect plugin template to start with.&lt;br /&gt;
&lt;br /&gt;
==Naming convention==&lt;br /&gt;
==File structure==&lt;br /&gt;
# Choose a name for your plugin.  We&#039;ll use &#039;sentry&#039; as an example below; change it to whatever name you have chosen.&lt;br /&gt;
# Under your Moodle installation root, create the directory &amp;lt;tt&amp;gt;/auth/sentry&amp;lt;/tt&amp;gt;.  It should be sibling to existing auth plugin directories: &#039;db&#039;, &#039;nologin&#039;, &#039;none&#039;, etc.&lt;br /&gt;
# Create the file &amp;lt;tt&amp;gt;/auth/sentry/auth.php&amp;lt;/tt&amp;gt;.  Within the file, create a class &amp;lt;tt&amp;gt;auth_plugin_sentry&amp;lt;/tt&amp;gt; that extends &amp;lt;tt&amp;gt;auth_plugin_base&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;/lib/authlib.php&amp;lt;/tt&amp;gt;.  (You will need to &amp;lt;code&amp;gt;require_once&amp;lt;/code&amp;gt; the authlib file.)&lt;br /&gt;
# Implement the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function in your &amp;lt;tt&amp;gt;auth.php&amp;lt;/tt&amp;gt; file, and create or override additional functions based on your plugin&#039;s requirements.&lt;br /&gt;
# Log in to your Moodle installation as a site administrator and find, in the site administrator block, the page &amp;quot;Users -&amp;gt; Authentication -&amp;gt; Manage authentication&amp;quot;.  You will see your plugin in the list, appearing as &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt;.  You can enable it and move it up and down in the order.  &#039;&#039;&#039;At this point, with the plugin enabled, your plugin is registered and will be used by Moodle in its authentication process.&#039;&#039;&#039;&lt;br /&gt;
# If you don&#039;t like seeing &amp;lt;nowiki&amp;gt;[[auth_sentrytitle]]&amp;lt;/nowiki&amp;gt; as the name of your plugin in the Moodle UI, you&#039;ll need to create language files for your plugin.  Do this by creating the directory &amp;lt;tt&amp;gt;/auth/sentry/lang&amp;lt;/tt&amp;gt;, and under it, a directory for each language that your installation needs to support.  (Example: &amp;lt;tt&amp;gt;/auth/sentry/lang/en&amp;lt;/tt&amp;gt;.)  Within each of these language directories, create a file called &amp;lt;tt&amp;gt;auth_sentry.php&amp;lt;/tt&amp;gt;.  That file should set the desired value for &amp;lt;code&amp;gt;$string[&#039;auth_sentrytitle&#039;] for that language (use $string[&#039;pluginname&#039;] for Moodle2)&amp;lt;/code&amp;gt;.  You can also set the plugin description by setting &amp;lt;code&amp;gt;$string[&#039;auth_sentrydescription&#039;]&amp;lt;/code&amp;gt;, and you can also assign other translatable strings that your plugin uses, in these files.  &#039;&#039;&#039;Note:&#039;&#039;&#039; A folder named like &#039;&#039;&#039;en&#039;&#039;&#039; may not work for everyone. Please refer to the lang folder under your moodle installation directory to get an idea about the language/locale codes used in your moodle installation. For example, the lang folder in own users system contained folders named &#039;&#039;&#039;en&#039;&#039;&#039; and &#039;&#039;&#039;zh-cn&#039;&#039;&#039;. He emulated the same in the lang folder of the auth plugin and the plugin picked up the title and description strings immediately. ([[Places_to_search_for_lang_strings|More info on how Moodle handles language]]).&lt;br /&gt;
# If you want to configure your plugin through the Moodle UI, implement &amp;lt;tt&amp;gt;config_form()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;process_config()&amp;lt;/tt&amp;gt; in the plugin class.  You might find it convenient to use the &#039;db&#039; plugin as a model for this.  The plugin&#039;s config settings can then be managed through the Manage authentication page by clicking on the Settings link for that plugin, and the values will be stored in the &amp;lt;tt&amp;gt;mdl_config_pluginstable&amp;lt;/tt&amp;gt; in the database.&lt;br /&gt;
&lt;br /&gt;
==Interfacing to API&#039;s==&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
That&#039;s the main outline, but a lot of interesting stuff happens in &amp;lt;tt&amp;gt;authenticate_user_login()&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
# It gets a list of enabled authentication plugins.&lt;br /&gt;
# It looks up the username in the mdl_user table to see if they are allowed to log in, and which authentication plugin handles their login requests. (This will be the plugin that handled their first-ever login request.)&lt;br /&gt;
# It creates a user object, which will contain the data from &amp;lt;tt&amp;gt;mdl_user&amp;lt;/tt&amp;gt; if the username is known; if not, it will be an empty object.&lt;br /&gt;
# It does the following with the authentication plugin (note that for a username unknown to Moodle, it will do these steps for each authenticated plugin until one succeeds or it has tried them all):&lt;br /&gt;
## Calls the &amp;lt;tt&amp;gt;user_login()&amp;lt;/tt&amp;gt; function provided by that plugin, which returns a boolean value based on whether the credentials authenticate or not. If the result is false (not authenticated), skips the rest of the steps below and continues to the next plugin.&lt;br /&gt;
## If the plugin authenticates against an external system (not Moodle&#039;s user database), its &amp;lt;tt&amp;gt;update_user_record()&amp;lt;/tt&amp;gt; function is called to get the user&#039;s name, contact info, etc.&lt;br /&gt;
## Creates the Moodle user record if it doesn&#039;t already exist.&lt;br /&gt;
## Calls the plugin&#039;s &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
## Notifies each enabled authentication plugin that the user successfully authenticated, by calling each one&#039;s &amp;lt;tt&amp;gt;user_authenticated_hook()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
# It returns the user object if everything was successful, or false if no plugin was able to successfully authenticate the credentials.&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_login($username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
This must be rewritten by plugin to return boolean value, returns true if the username and password work and false if they are wrong or don&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
===&amp;lt;tt&amp;gt;can_change_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can change users&#039; password.&lt;br /&gt;
&lt;br /&gt;
; Return type : boolean&lt;br /&gt;
; Default return value : false&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;change_password_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for changing the users&#039; passwords, or empty if the default URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_edit_profile()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if this authentication plugin can edit the users&#039; profile.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;edit_profile_url()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns the URL for editing users&#039; profile, or empty if the defaults URL can be used.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prevent_local_passwords()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Indicates if password hashes should be stored in local moodle database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update_password($user, $newpassword)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Update the user&#039;s password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_update($olduser, $newuser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Called when the user record is updated. It will modify the user information in external database.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_delete($olduser)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
User delete requested. Internal user record had been deleted.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_reset_password()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows resetting of internal password.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_signup($user, $notify=true)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sign up a new user ready for confirmation, password is passed in plaintext.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;can_confirm()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns true if plugin allows confirming of new users.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_confirm($username, $confirmsecret)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Confirm the new user as registered.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_exists($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Checks if user exists in external db.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;password_expire($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Returns number of days to user password expires.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;sync_roles()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Sync roles for this user - usually creator&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;get_userinfo($username)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Read user information from external database and returns it as array.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;config_form($config, $err, $user_fields)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Prints a form for configuring this authentication plugin. It&#039;s called from admin/auth.php, and outputs a full page with a form for configuring this plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;validate_form($form, $err)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Validate form data.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;process_config($config)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Processes and stores configuration data for this authentication plugin.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;loginpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of login page.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;user_authenticated_hook($user, $username, $password)&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Post authentication hook. This method is called from authenticate_user_login() for all enabled auth plugins.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;prelogout_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Pre logout hook.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;logoutpage_hook()&amp;lt;/tt&amp;gt;===&lt;br /&gt;
Hook for overriding behaviour of logout page.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Authentication API]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum]&lt;br /&gt;
* Moodle Docs [[:en:Manage authentication|Manage authentication]]&lt;br /&gt;
* [[:en:Authentication FAQ|Authentication FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Authentication]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[fr:Méthodes_d&#039;authentification]]&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/dev/index.php?title=Talk:Authentication_plugins&amp;diff=42339</id>
		<title>Talk:Authentication plugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/dev/index.php?title=Talk:Authentication_plugins&amp;diff=42339"/>
		<updated>2013-09-17T20:21:56Z</updated>

		<summary type="html">&lt;p&gt;Rrf5000: /* prevent_local_passwords() documentation */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To make the title and description translations of the plugin work, you must also create the class constructor.&lt;br /&gt;
&lt;br /&gt;
== prevent_local_passwords() documentation ==&lt;br /&gt;
&lt;br /&gt;
The current documentation states:&lt;br /&gt;
&lt;br /&gt;
:: Indicates if password hashes should be stored in local moodle database.&lt;br /&gt;
&lt;br /&gt;
The code in auth/none has no comments regarding this method.  Am I to assume that using &amp;quot;return false&amp;quot; allows password hashes to be stored in Moodle&#039;s database and &amp;quot;return true&amp;quot; &#039;&#039;prevents&#039;&#039; password hashes from being stored in Moodle&#039;s database?&lt;br /&gt;
&lt;br /&gt;
--[[User:Ryan Foster|Ryan Foster]] ([[User talk:Ryan Foster|talk]]) 04:21, 18 September 2013 (WST)&lt;/div&gt;</summary>
		<author><name>Rrf5000</name></author>
	</entry>
</feed>