3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * Change password form definition.
23 * @copyright 2006 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
29 require_once $CFG->libdir
.'/formslib.php';
31 class login_change_password_form
extends moodleform
{
33 function definition() {
36 $mform = $this->_form
;
38 $mform->addElement('header', '', get_string('changepassword'), '');
41 $mform->addElement('static', 'username', get_string('username'), $USER->username
);
43 if (!empty($CFG->passwordpolicy
)){
44 $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
46 $mform->addElement('password', 'password', get_string('oldpassword'));
47 $mform->addRule('password', get_string('required'), 'required', null, 'client');
48 $mform->setType('password', PARAM_RAW
);
50 $mform->addElement('password', 'newpassword1', get_string('newpassword'));
51 $mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
52 $mform->setType('newpassword1', PARAM_RAW
);
54 $mform->addElement('password', 'newpassword2', get_string('newpassword').' ('.get_String('again').')');
55 $mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
56 $mform->setType('newpassword2', PARAM_RAW
);
59 // hidden optional params
60 $mform->addElement('hidden', 'id', 0);
61 $mform->setType('id', PARAM_INT
);
64 if (get_user_preferences('auth_forcepasswordchange')) {
65 $this->add_action_buttons(false);
67 $this->add_action_buttons(true);
71 /// perform extra password change validation
72 function validation($data, $files) {
74 $errors = parent
::validation($data, $files);
78 // ignore submitted username
79 if (!$user = authenticate_user_login($USER->username
, $data['password'])) {
80 $errors['password'] = get_string('invalidlogin');
86 if ($data['newpassword1'] <> $data['newpassword2']) {
87 $errors['newpassword1'] = get_string('passwordsdiffer');
88 $errors['newpassword2'] = get_string('passwordsdiffer');
92 if ($data['password'] == $data['newpassword1']){
93 $errors['newpassword1'] = get_string('mustchangepassword');
94 $errors['newpassword2'] = get_string('mustchangepassword');
98 $errmsg = '';//prevents eclipse warnings
99 if (!check_password_policy($data['newpassword1'], $errmsg)) {
100 $errors['newpassword1'] = $errmsg;
101 $errors['newpassword2'] = $errmsg;