Automatically generated installer lang files
[moodle.git] / login / change_password_form.php
CommitLineData
6c3ef410 1<?php
1437f0a5 2
c30949a9
PS
3// This file is part of Moodle - http://moodle.org/
4//
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.
9//
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.
14//
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/>.
17
18/**
19 * Change password form definition.
20 *
21 * @package core
22 * @subpackage auth
23 * @copyright 2006 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27defined('MOODLE_INTERNAL') || die();
bfebaf64 28
1437f0a5 29require_once $CFG->libdir.'/formslib.php';
30
f07b9627 31class login_change_password_form extends moodleform {
1437f0a5 32
33 function definition() {
851481dc 34 global $USER, $CFG;
1437f0a5 35
c30949a9 36 $mform = $this->_form;
1437f0a5 37
38 $mform->addElement('header', '', get_string('changepassword'), '');
1437f0a5 39
40 // visible elements
fdf562fb 41 $mform->addElement('static', 'username', get_string('username'), $USER->username);
1437f0a5 42
3bf11ca4
DM
43 if (!empty($CFG->passwordpolicy)){
44 $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
851481dc 45 }
6bc1e5d5 46 $mform->addElement('password', 'password', get_string('oldpassword'));
47 $mform->addRule('password', get_string('required'), 'required', null, 'client');
48 $mform->setType('password', PARAM_RAW);
1437f0a5 49
50 $mform->addElement('password', 'newpassword1', get_string('newpassword'));
51 $mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
52 $mform->setType('newpassword1', PARAM_RAW);
53
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);
57
58
59 // hidden optional params
60 $mform->addElement('hidden', 'id', 0);
61 $mform->setType('id', PARAM_INT);
62
63 // buttons
f2d042c4 64 if (get_user_preferences('auth_forcepasswordchange')) {
b6d15dde 65 $this->add_action_buttons(false);
f2d042c4 66 } else {
67 $this->add_action_buttons(true);
5d2b6c1c 68 }
1437f0a5 69 }
70
71/// perform extra password change validation
a78890d5 72 function validation($data, $files) {
1437f0a5 73 global $USER;
a78890d5 74 $errors = parent::validation($data, $files);
1437f0a5 75
6bc1e5d5 76 update_login_count();
1437f0a5 77
6bc1e5d5 78 // ignore submitted username
32648682 79 if (!$user = authenticate_user_login($USER->username, $data['password'])) {
6bc1e5d5 80 $errors['password'] = get_string('invalidlogin');
1437f0a5 81 return $errors;
82 }
83
6bc1e5d5 84 reset_login_count();
1437f0a5 85
86 if ($data['newpassword1'] <> $data['newpassword2']) {
87 $errors['newpassword1'] = get_string('passwordsdiffer');
88 $errors['newpassword2'] = get_string('passwordsdiffer');
89 return $errors;
6bc1e5d5 90 }
91
92 if ($data['password'] == $data['newpassword1']){
1437f0a5 93 $errors['newpassword1'] = get_string('mustchangepassword');
94 $errors['newpassword2'] = get_string('mustchangepassword');
95 return $errors;
96 }
97
83022298 98 $errmsg = '';//prevents eclipse warnings
99 if (!check_password_policy($data['newpassword1'], $errmsg)) {
100 $errors['newpassword1'] = $errmsg;
101 $errors['newpassword2'] = $errmsg;
41eb7f32 102 return $errors;
83022298 103 }
104
a78890d5 105 return $errors;
1437f0a5 106 }
107}