diff --git a/js/functions.js b/js/functions.js index 53f82e960f..1bf638dfce 100644 --- a/js/functions.js +++ b/js/functions.js @@ -4766,7 +4766,7 @@ AJAX.registerOnload('functions.js', function(){ * method is selected * Used in user_password.php (Change Password link on index.php) */ - $(document).on("change", 'input[type=radio][name="pw_hash"]', function() { + $(document).on("change", 'select#select_authentication_plugin_cp', function() { if (this.value === 'sha256_password') { $('#ssl_reqd_warning_cp').show(); } else { diff --git a/libraries/display_change_password.lib.php b/libraries/display_change_password.lib.php index 0ed22b3a9f..2c99a993c3 100644 --- a/libraries/display_change_password.lib.php +++ b/libraries/display_change_password.lib.php @@ -79,52 +79,31 @@ function PMA_getHtmlForChangePassword($username, $hostname) . ''; $html .= '' - . '' . __('Password Hashing:') . ''; + . '' . __('Password Hashing:') . ''; $serverType = PMA_Util::getServerType(); + $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin( + 'change', + $username, + $hostname + ); + if (($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50507) || ($serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200) ) { - - $active_auth_plugins = PMA_getActiveAuthPlugins(); - - $default_auth_plugin = PMA_getCurrentAuthenticationPlugin( - 'change', $username, $hostname + $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown( + $username, $hostname, $orig_auth_plugin, 'change_pw', 'new' ); - $iter = 0; - $total_plugins = count($active_auth_plugins); - foreach ($active_auth_plugins as $plugin) { - if ($plugin['PLUGIN_NAME'] == 'mysql_old_password') { - continue; - } - - if ($iter != 0) { - $html .= ' '; - } - $html .= '' - . '' - . ''; - - if ($iter == $total_plugins - 2) { - $html .= ''; - } else if ($iter != $total_plugins - 1) { - $html .= ''; - } - $iter++; - } - - $html .= ''; + $html .= $auth_plugin_dropdown; + $html .= ''; + $html .= ''; $html .= ''; $html .= '
' . PMA_Message::notice( __( @@ -137,11 +116,11 @@ function PMA_getHtmlForChangePassword($username, $hostname) ->getDisplay() . '
'; } else { - $html .= '' - . '' - . '' + $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown( + $username, $hostname, $orig_auth_plugin, 'change_pw', 'old' + ); + + $html .= $auth_plugin_dropdown . '' . '' . ''; } diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 7dd06ff4d4..e2da8c5380 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -1411,6 +1411,50 @@ function PMA_getHtmlForGlobalPrivTableWithCheckboxes( return $html_output; } +/** + * Gets the currently active authentication plugins + * + * @param string $username User name + * @param string $hostname Host name + * @param string $orig_auth_plugin Default Authentication plugin + * @param string $mode are we creating a new user or are we just + * changing one? + * (allowed values: 'new', 'edit', 'change_pw') + * @param string $versions Is MySQL version newer or older than 5.5.7 + * + * @return string $html_output + */ +function PMA_getHtmlForAuthPluginsDropdown( + $username, + $hostname, + $orig_auth_plugin, + $mode = 'new', + $versions = 'new' +) { + $html_output = ''; + } else { + $html_output .= '' + . ''; + } + + return $html_output; +} /** * Gets the currently active authentication plugins * @@ -1710,6 +1754,12 @@ function PMA_getHtmlForLoginInformationFields( . ' ' . "\n" - . '' - . ''; } else { $html_output .= __('Password Hashing Method') - . ' ' . "\n" - . ''; + . ' ' . "\n"; + $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown( + $username, $hostname, $orig_auth_plugin, $mode, 'old' + ); } + $html_output .= $auth_plugin_dropdown; + + $html_output .= '
' + . PMA_Message::notice( + __( + 'This method requires using an \'SSL connection\' ' + . 'or an \'unencrypted connection that encrypts the password ' + . 'using RSA\'; while connecting to the server.' + ) + . PMA_Util::showMySQLDocu('sha256-authentication-plugin') + ) + ->getDisplay() + . '
'; + $html_output .= '' . "\n" - // Generate password added here via jQuery + // Generate password added here via jQuery . '' . "\n"; return $html_output; @@ -1898,14 +1935,19 @@ function PMA_updatePassword($err_url, $username, $hostname) // here $nopass could be == 1 if (empty($message)) { + $hashing_function = 'PASSWORD'; + if (PMA_Util::getServerType() == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706 ) { - if (! empty($_REQUEST['pw_hash']) && $_REQUEST['pw_hash'] != 'old') { + if (isset($_REQUEST['authentication_plugin']) + && $_REQUEST['authentication_plugin'] != 'mysql_old_password' + ) { $query_prefix = "ALTER USER '" . PMA_Util::sqlAddSlashes($username) . "'@'" . PMA_Util::sqlAddSlashes($hostname) . "'" - . " IDENTIFIED WITH " . $_REQUEST['pw_hash'] + . " IDENTIFIED WITH " + . $_REQUEST['authentication_plugin'] . " BY '"; } else { $query_prefix = "ALTER USER '" @@ -1919,28 +1961,64 @@ function PMA_updatePassword($err_url, $username, $hostname) $local_query = $query_prefix . PMA_Util::sqlAddSlashes($_POST['pma_pw']) . "'"; - } else { - if (! empty($_REQUEST['pw_hash']) - && $_REQUEST['pw_hash'] == 'mysql_old_password' - ) { - $hashing_function = 'OLD_PASSWORD'; - } elseif (! empty($_REQUEST['pw_hash']) - && $_REQUEST['pw_hash'] == 'sha256_password' - ) { - $hashing_function = 'PASSWORD'; + } else if ((PMA_Util::getServerType() == 'MySQL' + && PMA_MYSQL_INT_VERSION >= 50507) + || (PMA_Util::getServerType() == 'MariaDB' + && PMA_MYSQL_INT_VERSION >= 50200) + ) { + // Backup the old value, to be reset later + $row = $GLOBALS['dbi']->fetchSingleRow( + 'SELECT @@old_passwords;' + ); + $orig_value = $row['@@old_passwords']; - // Backup the old value, to be reset later - $row = $GLOBALS['dbi']->fetchSingleRow( - 'SELECT @@old_passwords;' - ); - $orig_value = $row['@@old_passwords']; + if (isset($_REQUEST['authentication_plugin']) + && $_REQUEST['authentication_plugin'] == 'mysql_native_password' + ) { + // Set the hashing method used by PASSWORD() + // to be 'mysql_native_password' type + $GLOBALS['dbi']->tryQuery('SET old_passwords = 0;'); + + } else if (isset($_REQUEST['authentication_plugin']) + && $_REQUEST['authentication_plugin'] == 'sha256_password' + ) { // Set the hashing method used by PASSWORD() // to be 'sha256_password' type - $GLOBALS['dbi']->tryQuery('SET old_passwords = 2;'); - } else { - $hashing_function = 'PASSWORD'; + $GLOBALS['dbi']->tryQuery('SET `old_passwords` = 2;'); } + $update_plugin_query = "UPDATE `mysql`.`user` SET" + . " `plugin` = '" . $_REQUEST['authentication_plugin'] . "'" + . " WHERE `User` = '" . $username . "' AND Host = '" + . $hostname . "';"; + + // Update the plugin for the user + $GLOBALS['dbi']->tryQuery($update_plugin_query) + or PMA_Util::mysqlDie( + $GLOBALS['dbi']->getError(), + $update_plugin_query, + false, $err_url + ); + + $sql_query = 'SET PASSWORD FOR \'' + . PMA_Util::sqlAddSlashes($username) + . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\' = ' + . (($_POST['pma_pw'] == '') + ? '\'\'' + : $hashing_function . '(\'' + . preg_replace('@.@s', '*', $_POST['pma_pw']) . '\')'); + + $local_query = 'SET PASSWORD FOR \'' + . PMA_Util::sqlAddSlashes($username) + . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\' = ' + . (($_POST['pma_pw'] == '') ? '\'\'' : $hashing_function + . '(\'' . PMA_Util::sqlAddSlashes($_POST['pma_pw']) . '\')'); + } else { + if (isset($_REQUEST['authentication_plugin']) + && $_REQUEST['authentication_plugin'] == 'mysql_native_password' + ) { + $GLOBALS['dbi']->tryQuery('SET `old_passwords` = 0;'); + } $sql_query = 'SET PASSWORD FOR \'' . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\' = ' diff --git a/user_password.php b/user_password.php index 71e5b4e3ce..55c78c970b 100644 --- a/user_password.php +++ b/user_password.php @@ -144,10 +144,16 @@ function PMA_changePassword($password, $message, $change_password_message) $curr_user = $row['user']; list($username, $hostname) = explode('@', $curr_user); - if (PMA_Util::getServerType() === 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706) { + $serverType = PMA_Util::getServerType(); - if (isset($_REQUEST['pw_hash']) && ! empty($_REQUEST['pw_hash'])) { - $orig_auth_plugin = $_REQUEST['pw_hash']; + if ($serverType === 'MySQL' + && PMA_MYSQL_INT_VERSION >= 50706 + ) { + + if (isset($_REQUEST['authentication_plugin']) + && ! empty($_REQUEST['authentication_plugin']) + ) { + $orig_auth_plugin = $_REQUEST['authentication_plugin']; } else { $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin( 'change', $username, $hostname @@ -158,11 +164,15 @@ function PMA_changePassword($password, $message, $change_password_message) . '\' IDENTIFIED WITH ' . $orig_auth_plugin . ' BY ' . (($password == '') ? '\'\'' : '\'***\''); } else { - // For MySQL versions 5.6.6+, + // For MySQL versions 5.5.7+ and MariaDB versions 5.2+, // explicitly set value of `old_passwords` so that // it does not give an error while using // the PASSWORD() function - if (PMA_MYSQL_INT_VERSION >= 50606) { + if (($serverType == 'MySQL' + && PMA_MYSQL_INT_VERSION >= 50507) + || ($serverType == 'MariaDB' + && PMA_MYSQL_INT_VERSION >= 50200) + ) { $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin( 'change', $username, $hostname );