2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Authentication Plugin: Manual Authentication
19 * Just does a simple check against the moodle database.
23 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
29 require_once($CFG->libdir
.'/authlib.php');
32 * Manual authentication plugin.
36 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 class auth_plugin_manual
extends auth_plugin_base
{
44 function auth_plugin_manual() {
45 $this->authtype
= 'manual';
46 $this->config
= get_config('auth/manual');
50 * Returns true if the username and password work and false if they are
51 * wrong or don't exist. (Non-mnet accounts only!)
53 * @param string $username The username
54 * @param string $password The password
55 * @return bool Authentication success or failure.
57 function user_login($username, $password) {
58 global $CFG, $DB, $USER;
59 if (!$user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id
))) {
62 if (!validate_internal_user_password($user, $password)) {
65 if ($password === 'changeme') {
66 // force the change - this is deprecated and it makes sense only for manual auth,
67 // because most other plugins can not change password easily or
68 // passwords are always specified by users
69 set_user_preference('auth_forcepasswordchange', true, $user->id
);
75 * Updates the user's password.
77 * Called when the user password is updated.
79 * @param object $user User table object
80 * @param string $newpassword Plaintext password
81 * @return boolean result
83 function user_update_password($user, $newpassword) {
84 $user = get_complete_user_data('id', $user->id
);
85 return update_internal_user_password($user, $newpassword);
88 function prevent_local_passwords() {
93 * Returns true if this authentication plugin is 'internal'.
97 function is_internal() {
102 * Returns true if this authentication plugin can change the user's
107 function can_change_password() {
112 * Returns the URL for changing the user's pw, or empty if the default can
117 function change_password_url() {
122 * Returns true if plugin allows resetting of internal password.
126 function can_reset_password() {
131 * Prints a form for configuring this authentication plugin.
133 * This function is called from admin/auth.php, and outputs a full page with
134 * a form for configuring this plugin.
136 * @param array $config An object containing all the data for this page.
137 * @param string $error
138 * @param array $user_fields
141 function config_form($config, $err, $user_fields) {
142 include 'config.html';
146 * Processes and stores configuration data for this authentication plugin.
148 * @param array $config
151 function process_config($config) {
156 * Confirm the new user as registered. This should normally not be used,
157 * but it may be necessary if the user auth_method is changed to manual
158 * before the user is confirmed.
160 * @param string $username
161 * @param string $confirmsecret
163 function user_confirm($username, $confirmsecret = null) {
166 $user = get_complete_user_data('username', $username);
169 if ($user->confirmed
) {
170 return AUTH_CONFIRM_ALREADY
;
172 $DB->set_field("user", "confirmed", 1, array("id"=>$user->id
));
173 if ($user->firstaccess
== 0) {
174 $DB->set_field("user", "firstaccess", time(), array("id"=>$user->id
));
176 return AUTH_CONFIRM_OK
;
179 return AUTH_CONFIRM_ERROR
;