user_password.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * displays and handles the form where the user can change his password
  5. * linked from index.php
  6. *
  7. * @package PhpMyAdmin
  8. */
  9. use PhpMyAdmin\Display\ChangePassword;
  10. use PhpMyAdmin\Message;
  11. use PhpMyAdmin\Response;
  12. use PhpMyAdmin\UserPassword;
  13. /**
  14. * Gets some core libraries
  15. */
  16. require_once './libraries/common.inc.php';
  17. $response = Response::getInstance();
  18. $header = $response->getHeader();
  19. $scripts = $header->getScripts();
  20. $scripts->addFile('server_privileges.js');
  21. $scripts->addFile('vendor/zxcvbn.js');
  22. $userPassword = new UserPassword();
  23. /**
  24. * Displays an error message and exits if the user isn't allowed to use this
  25. * script
  26. */
  27. if (! $GLOBALS['cfg']['ShowChgPassword']) {
  28. $GLOBALS['cfg']['ShowChgPassword'] = $GLOBALS['dbi']->selectDb('mysql');
  29. }
  30. if ($cfg['Server']['auth_type'] == 'config' || ! $cfg['ShowChgPassword']) {
  31. Message::error(
  32. __('You don\'t have sufficient privileges to be here right now!')
  33. )->display();
  34. exit;
  35. } // end if
  36. /**
  37. * If the "change password" form has been submitted, checks for valid values
  38. * and submit the query or logout
  39. */
  40. if (isset($_POST['nopass'])) {
  41. if ($_POST['nopass'] == '1') {
  42. $password = '';
  43. } else {
  44. $password = $_POST['pma_pw'];
  45. }
  46. $change_password_message = $userPassword->setChangePasswordMsg();
  47. $msg = $change_password_message['msg'];
  48. if (! $change_password_message['error']) {
  49. $userPassword->changePassword($password, $msg, $change_password_message);
  50. } else {
  51. $userPassword->getChangePassMessage($change_password_message);
  52. }
  53. }
  54. /**
  55. * If the "change password" form hasn't been submitted or the values submitted
  56. * aren't valid -> displays the form
  57. */
  58. // Displays an error message if required
  59. if (isset($msg)) {
  60. $msg->display();
  61. unset($msg);
  62. }
  63. echo ChangePassword::getHtml('change_pw', $username, $hostname);
  64. exit;