/manage/phpmyadminlite/user_password.php

https://gitlab.com/albert925/lading-ach · PHP · 142 lines · 64 code · 18 blank · 60 comment · 21 complexity · 681126a68a9fa8e23517705438ab74ca MD5 · raw file

  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 main.php
  6. *
  7. * @uses $GLOBALS['strUpdateProfileMessage']
  8. * @uses $GLOBALS['strBack']
  9. * @uses $GLOBALS['js_include']
  10. * @uses $GLOBALS['strChangePassword']
  11. * @uses $GLOBALS['strPasswordEmpty']
  12. * @uses $GLOBALS['strPasswordNotSame']
  13. * @uses $GLOBALS['strError']
  14. * @uses $GLOBALS['strNoRights']
  15. * @uses $cfg['ShowChgPassword']
  16. * @uses $cfg['Server']['auth_type']
  17. * @uses PMA_DBI_select_db()
  18. * @uses PMA_DBI_try_query()
  19. * @uses PMA_DBI_getError()
  20. * @uses PMA_sanitize()
  21. * @uses PMA_generate_common_url()
  22. * @uses PMA_isValid()
  23. * @uses PMA_mysqlDie()
  24. * @uses PMA_setCookie()
  25. * @uses PMA_blowfish_encrypt()
  26. * @uses PMA_showMessage()
  27. * @uses define()
  28. * @version $Id$
  29. * @package phpMyAdmin
  30. */
  31. /**
  32. * no need for variables importing
  33. * @ignore
  34. */
  35. if (! defined('PMA_NO_VARIABLES_IMPORT')) {
  36. define('PMA_NO_VARIABLES_IMPORT', true);
  37. }
  38. /**
  39. * Gets some core libraries
  40. */
  41. require_once './libraries/common.inc.php';
  42. /**
  43. * Displays an error message and exits if the user isn't allowed to use this
  44. * script
  45. */
  46. if (!$cfg['ShowChgPassword']) {
  47. $cfg['ShowChgPassword'] = PMA_DBI_select_db('mysql');
  48. }
  49. if ($cfg['Server']['auth_type'] == 'config' || !$cfg['ShowChgPassword']) {
  50. require_once './libraries/header.inc.php';
  51. PMA_Message::error('strNoRights')->display();
  52. require_once './libraries/footer.inc.php';
  53. } // end if
  54. /**
  55. * If the "change password" form has been submitted, checks for valid values
  56. * and submit the query or logout
  57. */
  58. if (isset($_REQUEST['nopass'])) {
  59. // similar logic in server_privileges.php
  60. $_error = false;
  61. if ($_REQUEST['nopass'] == '1') {
  62. $password = '';
  63. } elseif (empty($_REQUEST['pma_pw']) || empty($_REQUEST['pma_pw2'])) {
  64. $message = PMA_Message::error('strPasswordEmpty');
  65. $_error = true;
  66. } elseif ($_REQUEST['pma_pw'] != $_REQUEST['pma_pw2']) {
  67. $message = PMA_Message::error('strPasswordNotSame');
  68. $_error = true;
  69. } else {
  70. $password = $_REQUEST['pma_pw'];
  71. }
  72. if (! $_error) {
  73. // Defines the url to return to in case of error in the sql statement
  74. $_url_params = array();
  75. $err_url = 'user_password.php' . PMA_generate_common_url($_url_params);
  76. if (PMA_isValid($_REQUEST['pw_hash'], 'identical', 'old')) {
  77. $hashing_function = 'OLD_PASSWORD';
  78. } else {
  79. $hashing_function = 'PASSWORD';
  80. }
  81. $sql_query = 'SET password = ' . (($password == '') ? '\'\'' : $hashing_function . '(\'***\')');
  82. $local_query = 'SET password = ' . (($password == '') ? '\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($password) . '\')');
  83. $result = @PMA_DBI_try_query($local_query)
  84. or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, false, $err_url);
  85. // Changes password cookie if required
  86. // Duration = till the browser is closed for password (we don't want this to be saved)
  87. if ($cfg['Server']['auth_type'] == 'cookie') {
  88. PMA_setCookie('pmaPass-' . $server,
  89. PMA_blowfish_encrypt($password, $GLOBALS['cfg']['blowfish_secret']));
  90. } // end if
  91. // For http auth. mode, the "back" link will also enforce new
  92. // authentication
  93. if ($cfg['Server']['auth_type'] == 'http') {
  94. $_url_params['old_usr'] = 'relog';
  95. }
  96. // Displays the page
  97. require_once './libraries/header.inc.php';
  98. echo '<h1>' . $strChangePassword . '</h1>' . "\n\n";
  99. PMA_showMessage($strUpdateProfileMessage, $sql_query, 'success');
  100. ?>
  101. <a href="index.php<?php echo PMA_generate_common_url($_url_params); ?>" target="_parent">
  102. <strong><?php echo $strBack; ?></strong></a>
  103. <?php
  104. require_once './libraries/footer.inc.php';
  105. } // end if
  106. } // end if
  107. /**
  108. * If the "change password" form hasn't been submitted or the values submitted
  109. * aren't valid -> displays the form
  110. */
  111. // Loads the headers
  112. $GLOBALS['js_include'][] = 'server_privileges.js';
  113. require_once './libraries/header.inc.php';
  114. echo '<h1>' . $strChangePassword . '</h1>' . "\n\n";
  115. // Displays an error message if required
  116. if (isset($message)) {
  117. $message->display();
  118. }
  119. require_once './libraries/display_change_password.lib.php';
  120. /**
  121. * Displays the footer
  122. */
  123. require_once './libraries/footer.inc.php';
  124. ?>