2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * displays and handles the form where the user can change his password
7 * @uses $GLOBALS['js_include']
8 * @uses $cfg['ShowChgPassword']
9 * @uses $cfg['Server']['auth_type']
10 * @uses PMA_DBI_select_db()
11 * @uses PMA_DBI_try_query()
12 * @uses PMA_DBI_getError()
13 * @uses PMA_sanitize()
14 * @uses PMA_generate_common_url()
16 * @uses PMA_mysqlDie()
17 * @uses $GLOBALS['PMA_Config']->setCookie()
18 * @uses PMA_blowfish_encrypt()
19 * @uses PMA_showMessage()
25 * no need for variables importing
28 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
29 define('PMA_NO_VARIABLES_IMPORT', true);
33 * Gets some core libraries
35 require_once './libraries/common.inc.php';
37 $GLOBALS['js_include'][] = 'server_privileges.js';
38 $GLOBALS['js_include'][] = 'password_generation.js';
41 * Displays an error message and exits if the user isn't allowed to use this
44 if (!$cfg['ShowChgPassword']) {
45 $cfg['ShowChgPassword'] = PMA_DBI_select_db('mysql');
47 if ($cfg['Server']['auth_type'] == 'config' ||
!$cfg['ShowChgPassword']) {
48 require_once './libraries/header.inc.php';
49 PMA_Message
::error(__('You don\'t have sufficient privileges to be here right now!'))->display();
50 require './libraries/footer.inc.php';
55 * If the "change password" form has been submitted, checks for valid values
56 * and submit the query or logout
58 if (isset($_REQUEST['nopass'])) {
59 // similar logic in server_privileges.php
62 if ($_REQUEST['nopass'] == '1') {
64 } elseif (empty($_REQUEST['pma_pw']) ||
empty($_REQUEST['pma_pw2'])) {
65 $message = PMA_Message
::error(__('The password is empty!'));
67 } elseif ($_REQUEST['pma_pw'] != $_REQUEST['pma_pw2']) {
68 $message = PMA_Message
::error(__('The passwords aren\'t the same!'));
71 $password = $_REQUEST['pma_pw'];
76 // Defines the url to return to in case of error in the sql statement
77 $_url_params = array();
79 $err_url = 'user_password.php' . PMA_generate_common_url($_url_params);
80 if (PMA_isValid($_REQUEST['pw_hash'], 'identical', 'old')) {
81 $hashing_function = 'OLD_PASSWORD';
83 $hashing_function = 'PASSWORD';
86 $sql_query = 'SET password = ' . (($password == '') ?
'\'\'' : $hashing_function . '(\'***\')');
87 $local_query = 'SET password = ' . (($password == '') ?
'\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($password) . '\')');
88 $result = @PMA_DBI_try_query
($local_query)
89 or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, false, $err_url);
91 // Changes password cookie if required
92 // Duration = till the browser is closed for password (we don't want this to be saved)
93 if ($cfg['Server']['auth_type'] == 'cookie') {
94 $GLOBALS['PMA_Config']->setCookie('pmaPass-' . $server,
95 PMA_blowfish_encrypt($password, $GLOBALS['cfg']['blowfish_secret']));
98 // For http auth. mode, the "back" link will also enforce new
100 if ($cfg['Server']['auth_type'] == 'http') {
101 $_url_params['old_usr'] = 'relog';
105 require_once './libraries/header.inc.php';
106 echo '<h1>' . __('Change password') . '</h1>' . "\n\n";
107 PMA_showMessage(__('The profile has been updated.'), $sql_query, 'success');
109 <a href
="index.php<?php echo PMA_generate_common_url($_url_params); ?>" target
="_parent">
110 <strong
><?php
echo __('Back'); ?
></strong
></a
>
112 require './libraries/footer.inc.php';
118 * If the "change password" form hasn't been submitted or the values submitted
119 * aren't valid -> displays the form
122 require_once './libraries/header.inc.php';
124 echo '<h1>' . __('Change password') . '</h1>' . "\n\n";
126 // Displays an error message if required
127 if (isset($message)) {
131 require_once './libraries/display_change_password.lib.php';
134 * Displays the footer
136 require './libraries/footer.inc.php';