MDL-15683, get query string instead of calling me().
[moodle-linuxchix.git] / login / change_password_form.php
blob7b34e56b5e997ac037dd80c3c4977eb49ada2b19
1 <?php //$Id$
3 require_once $CFG->libdir.'/formslib.php';
5 class login_change_password_form extends moodleform {
7 function definition() {
8 global $USER;
10 $mform =& $this->_form;
12 $mform->addElement('header', '', get_string('changepassword'), '');
14 // visible elements
15 $mform->addElement('static', 'username', get_string('username'), $USER->username);
17 $mform->addElement('password', 'password', get_string('oldpassword'));
18 $mform->addRule('password', get_string('required'), 'required', null, 'client');
19 $mform->setType('password', PARAM_RAW);
21 $mform->addElement('password', 'newpassword1', get_string('newpassword'));
22 $mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
23 $mform->setType('newpassword1', PARAM_RAW);
25 $mform->addElement('password', 'newpassword2', get_string('newpassword').' ('.get_String('again').')');
26 $mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
27 $mform->setType('newpassword2', PARAM_RAW);
30 // hidden optional params
31 $mform->addElement('hidden', 'id', 0);
32 $mform->setType('id', PARAM_INT);
34 // buttons
35 if (get_user_preferences('auth_forcepasswordchange')) {
36 $this->add_action_buttons(false);
37 } else {
38 $this->add_action_buttons(true);
42 /// perform extra password change validation
43 function validation($data, $files) {
44 global $USER;
45 $errors = parent::validation($data, $files);
47 update_login_count();
49 // ignore submitted username
50 if (!$user = authenticate_user_login($USER->username, $data['password'])) {
51 $errors['password'] = get_string('invalidlogin');
52 return $errors;
55 reset_login_count();
57 if ($data['newpassword1'] <> $data['newpassword2']) {
58 $errors['newpassword1'] = get_string('passwordsdiffer');
59 $errors['newpassword2'] = get_string('passwordsdiffer');
60 return $errors;
63 if ($data['password'] == $data['newpassword1']){
64 $errors['newpassword1'] = get_string('mustchangepassword');
65 $errors['newpassword2'] = get_string('mustchangepassword');
66 return $errors;
69 $errmsg = '';//prevents eclipse warnings
70 if (!check_password_policy($data['newpassword1'], $errmsg)) {
71 $errors['newpassword1'] = $errmsg;
72 $errors['newpassword2'] = $errmsg;
73 return $errors;
76 return $errors;