PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/login/change_password_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 104 lines | 56 code | 21 blank | 27 comment | 9 complexity | 958b474685d196220ad3e334eec173c9 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  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.
  8. //
  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.
  13. //
  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/>.
  16. /**
  17. * Change password form definition.
  18. *
  19. * @package core
  20. * @subpackage auth
  21. * @copyright 2006 Petr Skoda {@link http://skodak.org}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. defined('MOODLE_INTERNAL') || die();
  25. require_once $CFG->libdir.'/formslib.php';
  26. class login_change_password_form extends moodleform {
  27. function definition() {
  28. global $USER, $CFG;
  29. $mform = $this->_form;
  30. $mform->setDisableShortforms(true);
  31. $mform->addElement('header', 'changepassword', get_string('changepassword'), '');
  32. // visible elements
  33. $mform->addElement('static', 'username', get_string('username'), $USER->username);
  34. if (!empty($CFG->passwordpolicy)){
  35. $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
  36. }
  37. $mform->addElement('password', 'password', get_string('oldpassword'));
  38. $mform->addRule('password', get_string('required'), 'required', null, 'client');
  39. $mform->setType('password', PARAM_RAW);
  40. $mform->addElement('password', 'newpassword1', get_string('newpassword'));
  41. $mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
  42. $mform->setType('newpassword1', PARAM_RAW);
  43. $mform->addElement('password', 'newpassword2', get_string('newpassword').' ('.get_String('again').')');
  44. $mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
  45. $mform->setType('newpassword2', PARAM_RAW);
  46. // hidden optional params
  47. $mform->addElement('hidden', 'id', 0);
  48. $mform->setType('id', PARAM_INT);
  49. // buttons
  50. if (get_user_preferences('auth_forcepasswordchange')) {
  51. $this->add_action_buttons(false);
  52. } else {
  53. $this->add_action_buttons(true);
  54. }
  55. }
  56. /// perform extra password change validation
  57. function validation($data, $files) {
  58. global $USER;
  59. $errors = parent::validation($data, $files);
  60. // ignore submitted username
  61. if (!$user = authenticate_user_login($USER->username, $data['password'], true)) {
  62. $errors['password'] = get_string('invalidlogin');
  63. return $errors;
  64. }
  65. if ($data['newpassword1'] <> $data['newpassword2']) {
  66. $errors['newpassword1'] = get_string('passwordsdiffer');
  67. $errors['newpassword2'] = get_string('passwordsdiffer');
  68. return $errors;
  69. }
  70. if ($data['password'] == $data['newpassword1']){
  71. $errors['newpassword1'] = get_string('mustchangepassword');
  72. $errors['newpassword2'] = get_string('mustchangepassword');
  73. return $errors;
  74. }
  75. $errmsg = '';//prevents eclipse warnings
  76. if (!check_password_policy($data['newpassword1'], $errmsg)) {
  77. $errors['newpassword1'] = $errmsg;
  78. $errors['newpassword2'] = $errmsg;
  79. return $errors;
  80. }
  81. return $errors;
  82. }
  83. }