ChangePassword.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. . 'onkeyup="checkPasswordStrength($(this).val(), $(\'#change_password_strength_meter\'), meter_obj_label = $(\'#change_password_strength\'), PMA_commonParams.get(\'user\'));" '
  77. . $chg_evt_handler . '="nopass[1].checked = true" />'
  78. . '<span>Strength:</span> '
  79. . '<meter max="4" id="change_password_strength_meter" name="pw_meter"></meter> '
  80. . '<span id="change_password_strength" name="pw_strength">Good</span>'
  81. . '<br>' . __('Re-type:') . '&nbsp;'
  82. . '<input type="password" name="pma_pw2" id="text_pma_change_pw2" size="10" '
  83. . 'class="textfield"'
  84. . $chg_evt_handler . '="nopass[1].checked = true" />'
  85. . '</td>'
  86. . '</tr>';
  87. $serverType = Util::getServerType();
  88. $serverVersion = $GLOBALS['dbi']->getVersion();
  89. $orig_auth_plugin = Privileges::getCurrentAuthenticationPlugin(
  90. 'change',
  91. $username,
  92. $hostname
  93. );
  94. if (($serverType == 'MySQL'
  95. && $serverVersion >= 50507)
  96. || ($serverType == 'MariaDB'
  97. && $serverVersion >= 50200)
  98. ) {
  99. // Provide this option only for 5.7.6+
  100. // OR for privileged users in 5.5.7+
  101. if (($serverType == 'MySQL'
  102. && $serverVersion >= 50706)
  103. || ($GLOBALS['dbi']->isSuperuser() && $mode == 'edit_other')
  104. ) {
  105. $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown(
  106. $orig_auth_plugin, 'change_pw', 'new'
  107. );
  108. $html .= '<tr class="vmiddle">'
  109. . '<td>' . __('Password Hashing:') . '</td><td>';
  110. $html .= $auth_plugin_dropdown;
  111. $html .= '</td></tr>'
  112. . '<tr id="tr_element_before_generate_password"></tr>'
  113. . '</table>';
  114. $html .= '<div'
  115. . ($orig_auth_plugin != 'sha256_password'
  116. ? ' class="hide"'
  117. : '')
  118. . ' id="ssl_reqd_warning_cp">'
  119. . Message::notice(
  120. __(
  121. 'This method requires using an \'<i>SSL connection</i>\' '
  122. . 'or an \'<i>unencrypted connection that encrypts the '
  123. . 'password using RSA</i>\'; while connecting to the server.'
  124. )
  125. . Util::showMySQLDocu(
  126. 'sha256-authentication-plugin'
  127. )
  128. )
  129. ->getDisplay()
  130. . '</div>';
  131. } else {
  132. $html .= '<tr id="tr_element_before_generate_password"></tr>'
  133. . '</table>';
  134. }
  135. } else {
  136. $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown(
  137. $orig_auth_plugin, 'change_pw', 'old'
  138. );
  139. $html .= '<tr class="vmiddle">'
  140. . '<td>' . __('Password Hashing:') . '</td><td>';
  141. $html .= $auth_plugin_dropdown . '</td></tr>'
  142. . '<tr id="tr_element_before_generate_password"></tr>'
  143. . '</table>';
  144. }
  145. $html .= '</fieldset>'
  146. . '<fieldset id="fieldset_change_password_footer" class="tblFooters">'
  147. . '<input type="hidden" name="change_pw" value="1" />'
  148. . '<input type="submit" value="' . __('Go') . '" />'
  149. . '</fieldset>'
  150. . '</form>';
  151. return $html;
  152. }
  153. }