ChangePassword.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Displays form for password change
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Display;
  9. use PhpMyAdmin\Message;
  10. use PhpMyAdmin\Server\Privileges;
  11. use PhpMyAdmin\Url;
  12. use PhpMyAdmin\Util;
  13. /**
  14. * Displays form for password change
  15. *
  16. * @package PhpMyAdmin
  17. */
  18. class ChangePassword
  19. {
  20. /**
  21. * Get HTML for the Change password dialog
  22. *
  23. * @param string $mode where is the function being called?
  24. * values : 'change_pw' or 'edit_other'
  25. * @param string $username username
  26. * @param string $hostname hostname
  27. *
  28. * @return string html snippet
  29. */
  30. public static function getHtml($mode, $username, $hostname)
  31. {
  32. /**
  33. * autocomplete feature of IE kills the "onchange" event handler and it
  34. * must be replaced by the "onpropertychange" one in this case
  35. */
  36. $chg_evt_handler = 'onchange';
  37. $is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php';
  38. $html = '<form method="post" id="change_password_form" '
  39. . 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" '
  40. . 'name="chgPassword" '
  41. . 'class="' . ($is_privileges ? 'submenu-item' : '') . '">';
  42. $html .= Url::getHiddenInputs();
  43. if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) {
  44. $html .= '<input type="hidden" name="username" '
  45. . 'value="' . htmlspecialchars($username) . '" />'
  46. . '<input type="hidden" name="hostname" '
  47. . 'value="' . htmlspecialchars($hostname) . '" />';
  48. }
  49. $html .= '<fieldset id="fieldset_change_password">'
  50. . '<legend'
  51. . ($is_privileges
  52. ? ' data-submenu-label="' . __('Change password') . '"'
  53. : ''
  54. )
  55. . '>' . __('Change password') . '</legend>'
  56. . '<table class="data noclick">'
  57. . '<tr>'
  58. . '<td colspan="2">'
  59. . '<input type="radio" name="nopass" value="1" id="nopass_1" '
  60. . 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; '
  61. . 'this.checked = true" />'
  62. . '<label for="nopass_1">' . __('No Password') . '</label>'
  63. . '</td>'
  64. . '</tr>'
  65. . '<tr class="vmiddle">'
  66. . '<td>'
  67. . '<input type="radio" name="nopass" value="0" id="nopass_0" '
  68. . 'onclick="document.getElementById(\'text_pma_change_pw\').focus();" '
  69. . 'checked="checked" />'
  70. . '<label for="nopass_0">' . __('Password:') . '&nbsp;</label>'
  71. . '</td>'
  72. . '<td>'
  73. . __('Enter:') . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp'
  74. . '<input type="password" name="pma_pw" id="text_pma_change_pw" size="10" '
  75. . 'class="textfield"'
  76. . $chg_evt_handler . '="nopass[1].checked = true" />'
  77. . '<span>Strength:</span> '
  78. . '<meter max="4" id="change_password_strength_meter" name="pw_meter"></meter> '
  79. . '<span id="change_password_strength" name="pw_strength">Good</span>'
  80. . '<br>' . __('Re-type:') . '&nbsp;'
  81. . '<input type="password" name="pma_pw2" id="text_pma_change_pw2" size="10" '
  82. . 'class="textfield"'
  83. . $chg_evt_handler . '="nopass[1].checked = true" />'
  84. . '</td>'
  85. . '</tr>';
  86. $serverType = Util::getServerType();
  87. $serverVersion = $GLOBALS['dbi']->getVersion();
  88. $orig_auth_plugin = Privileges::getCurrentAuthenticationPlugin(
  89. 'change',
  90. $username,
  91. $hostname
  92. );
  93. if (($serverType == 'MySQL'
  94. && $serverVersion >= 50507)
  95. || ($serverType == 'MariaDB'
  96. && $serverVersion >= 50200)
  97. ) {
  98. // Provide this option only for 5.7.6+
  99. // OR for privileged users in 5.5.7+
  100. if (($serverType == 'MySQL'
  101. && $serverVersion >= 50706)
  102. || ($GLOBALS['dbi']->isSuperuser() && $mode == 'edit_other')
  103. ) {
  104. $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown(
  105. $orig_auth_plugin, 'change_pw', 'new'
  106. );
  107. $html .= '<tr class="vmiddle">'
  108. . '<td>' . __('Password Hashing:') . '</td><td>';
  109. $html .= $auth_plugin_dropdown;
  110. $html .= '</td></tr>'
  111. . '<tr id="tr_element_before_generate_password"></tr>'
  112. . '</table>';
  113. $html .= '<div'
  114. . ($orig_auth_plugin != 'sha256_password'
  115. ? ' class="hide"'
  116. : '')
  117. . ' id="ssl_reqd_warning_cp">'
  118. . Message::notice(
  119. __(
  120. 'This method requires using an \'<i>SSL connection</i>\' '
  121. . 'or an \'<i>unencrypted connection that encrypts the '
  122. . 'password using RSA</i>\'; while connecting to the server.'
  123. )
  124. . Util::showMySQLDocu(
  125. 'sha256-authentication-plugin'
  126. )
  127. )
  128. ->getDisplay()
  129. . '</div>';
  130. } else {
  131. $html .= '<tr id="tr_element_before_generate_password"></tr>'
  132. . '</table>';
  133. }
  134. } else {
  135. $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown(
  136. $orig_auth_plugin, 'change_pw', 'old'
  137. );
  138. $html .= '<tr class="vmiddle">'
  139. . '<td>' . __('Password Hashing:') . '</td><td>';
  140. $html .= $auth_plugin_dropdown . '</td></tr>'
  141. . '<tr id="tr_element_before_generate_password"></tr>'
  142. . '</table>';
  143. }
  144. $html .= '</fieldset>'
  145. . '<fieldset id="fieldset_change_password_footer" class="tblFooters">'
  146. . '<input type="hidden" name="change_pw" value="1" />'
  147. . '<input type="submit" value="' . __('Go') . '" />'
  148. . '</fieldset>'
  149. . '</form>';
  150. return $html;
  151. }
  152. }