3 require_once $CFG->libdir
.'/formslib.php';
5 class login_change_password_form
extends moodleform
{
7 function definition() {
10 $mform =& $this->_form
;
12 $mform->addElement('header', '', get_string('changepassword'), '');
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
);
35 if (get_user_preferences('auth_forcepasswordchange')) {
36 $this->add_action_buttons(false);
38 $this->add_action_buttons(true);
42 /// perform extra password change validation
43 function validation($data){
49 // ignore submitted username
50 if (!$user = authenticate_user_login($USER->username
, $data['password'])) {
51 $errors['password'] = get_string('invalidlogin');
57 if ($data['newpassword1'] <> $data['newpassword2']) {
58 $errors['newpassword1'] = get_string('passwordsdiffer');
59 $errors['newpassword2'] = get_string('passwordsdiffer');
63 if ($data['password'] == $data['newpassword1']){
64 $errors['newpassword1'] = get_string('mustchangepassword');
65 $errors['newpassword2'] = get_string('mustchangepassword');
69 $errmsg = '';//prevents eclipse warnings
70 if (!check_password_policy($data['newpassword1'], $errmsg)) {
71 $errors['newpassword1'] = $errmsg;
72 $errors['newpassword2'] = $errmsg;