Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / libraries / display_change_password.lib.php
blobd72009bc6175a76cd31f275b04306f48daa544ff
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Displays form for password change
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\Message;
10 /**
11 * Get HTML for the Change password dialog
13 * @param string $mode where is the function being called?
14 * values : 'change_pw' or 'edit_other'
15 * @param string $username username
16 * @param string $hostname hostname
18 * @return string html snippet
20 function PMA_getHtmlForChangePassword($mode, $username, $hostname)
22 /**
23 * autocomplete feature of IE kills the "onchange" event handler and it
24 * must be replaced by the "onpropertychange" one in this case
26 $chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE'
27 && PMA_USR_BROWSER_VER >= 5
28 && PMA_USR_BROWSER_VER < 7)
29 ? 'onpropertychange'
30 : 'onchange';
32 $is_privileges = basename($_SERVER['SCRIPT_NAME']) === 'server_privileges.php';
34 $html = '<form method="post" id="change_password_form" '
35 . 'action="' . basename($GLOBALS['PMA_PHP_SELF']) . '" '
36 . 'name="chgPassword" '
37 . 'class="' . ($is_privileges ? 'submenu-item' : '') . '">';
39 $html .= PMA_URL_getHiddenInputs();
41 if (strpos($GLOBALS['PMA_PHP_SELF'], 'server_privileges') !== false) {
42 $html .= '<input type="hidden" name="username" '
43 . 'value="' . htmlspecialchars($username) . '" />'
44 . '<input type="hidden" name="hostname" '
45 . 'value="' . htmlspecialchars($hostname) . '" />';
47 $html .= '<fieldset id="fieldset_change_password">'
48 . '<legend'
49 . ($is_privileges
50 ? ' data-submenu-label="' . __('Change password') . '"'
51 : ''
53 . '>' . __('Change password') . '</legend>'
54 . '<table class="data noclick">'
55 . '<tr class="odd">'
56 . '<td colspan="2">'
57 . '<input type="radio" name="nopass" value="1" id="nopass_1" '
58 . 'onclick="pma_pw.value = \'\'; pma_pw2.value = \'\'; '
59 . 'this.checked = true" />'
60 . '<label for="nopass_1">' . __('No Password') . '</label>'
61 . '</td>'
62 . '</tr>'
63 . '<tr class="even vmiddle">'
64 . '<td>'
65 . '<input type="radio" name="nopass" value="0" id="nopass_0" '
66 . 'onclick="document.getElementById(\'text_pma_pw\').focus();" '
67 . 'checked="checked" />'
68 . '<label for="nopass_0">' . __('Password:') . '&nbsp;</label>'
69 . '</td>'
70 . '<td>'
71 . '<input type="password" name="pma_pw" id="text_pma_pw" size="10" '
72 . 'class="textfield"'
73 . $chg_evt_handler . '="nopass[1].checked = true" />'
74 . '&nbsp;&nbsp;' . __('Re-type:') . '&nbsp;'
75 . '<input type="password" name="pma_pw2" id="text_pma_pw2" size="10" '
76 . 'class="textfield"'
77 . $chg_evt_handler . '="nopass[1].checked = true" />'
78 . '</td>'
79 . '</tr>';
81 $serverType = PMA\libraries\Util::getServerType();
82 $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin(
83 'change',
84 $username,
85 $hostname
87 $is_superuser = $GLOBALS['dbi']->isSuperuser();
89 if (($serverType == 'MySQL'
90 && PMA_MYSQL_INT_VERSION >= 50507)
91 || ($serverType == 'MariaDB'
92 && PMA_MYSQL_INT_VERSION >= 50200)
93 ) {
94 // Provide this option only for 5.7.6+
95 // OR for privileged users in 5.5.7+
96 if (($serverType == 'MySQL'
97 && PMA_MYSQL_INT_VERSION >= 50706)
98 || ($is_superuser && $mode == 'edit_other')
99 ) {
100 $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown(
101 $orig_auth_plugin, 'change_pw', 'new'
104 $html .= '<tr class="vmiddle">'
105 . '<td>' . __('Password Hashing:') . '</td><td>';
106 $html .= $auth_plugin_dropdown;
107 $html .= '</td></tr>'
108 . '<tr id="tr_element_before_generate_password"></tr>'
109 . '</table>';
111 $html .= '<div '
112 . ($orig_auth_plugin != 'sha256_password'
113 ? 'style="display:none"'
114 : '')
115 . ' id="ssl_reqd_warning_cp">'
116 . Message::notice(
118 'This method requires using an \'<i>SSL connection</i>\' '
119 . 'or an \'<i>unencrypted connection that encrypts the '
120 . 'password using RSA</i>\'; while connecting to the server.'
122 . PMA\libraries\Util::showMySQLDocu(
123 'sha256-authentication-plugin'
126 ->getDisplay()
127 . '</div>';
128 } else {
129 $html .= '<tr id="tr_element_before_generate_password"></tr>'
130 . '</table>';
132 } else {
133 $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown(
134 $orig_auth_plugin, 'change_pw', 'old'
137 $html .= '<tr class="vmiddle">'
138 . '<td>' . __('Password Hashing:') . '</td><td>';
139 $html .= $auth_plugin_dropdown . '</td></tr>'
140 . '<tr id="tr_element_before_generate_password"></tr>'
141 . '</table>';
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;