move remaining old-format messages to the script that uses them, when possible
[phpmyadmin/crack.git] / user_password.php
blob9bfa280d0095835d1f6ac85c58c0e4ca245b030a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * displays and handles the form where the user can change his password
5 * linked from main.php
7 * @uses __('The profile has been updated.')
8 * @uses __('Back')
9 * @uses $GLOBALS['js_include']
10 * @uses __('Change password')
11 * @uses __('The password is empty!')
12 * @uses __('The passwords aren't the same!')
13 * @uses __('Error')
14 * @uses __('You don\'t have sufficient privileges to be here right now!')
15 * @uses $cfg['ShowChgPassword']
16 * @uses $cfg['Server']['auth_type']
17 * @uses PMA_DBI_select_db()
18 * @uses PMA_DBI_try_query()
19 * @uses PMA_DBI_getError()
20 * @uses PMA_sanitize()
21 * @uses PMA_generate_common_url()
22 * @uses PMA_isValid()
23 * @uses PMA_mysqlDie()
24 * @uses $GLOBALS['PMA_Config']->setCookie()
25 * @uses PMA_blowfish_encrypt()
26 * @uses PMA_showMessage()
27 * @uses define()
28 * @version $Id$
29 * @package phpMyAdmin
32 /**
33 * no need for variables importing
34 * @ignore
36 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
37 define('PMA_NO_VARIABLES_IMPORT', true);
40 /**
41 * Gets some core libraries
43 require_once './libraries/common.inc.php';
45 /**
46 * Displays an error message and exits if the user isn't allowed to use this
47 * script
49 if (!$cfg['ShowChgPassword']) {
50 $cfg['ShowChgPassword'] = PMA_DBI_select_db('mysql');
52 if ($cfg['Server']['auth_type'] == 'config' || !$cfg['ShowChgPassword']) {
53 require_once './libraries/header.inc.php';
54 PMA_Message::error(__('You don\'t have sufficient privileges to be here right now!'))->display();
55 require_once './libraries/footer.inc.php';
56 } // end if
59 /**
60 * If the "change password" form has been submitted, checks for valid values
61 * and submit the query or logout
63 if (isset($_REQUEST['nopass'])) {
64 // similar logic in server_privileges.php
65 $_error = false;
67 if ($_REQUEST['nopass'] == '1') {
68 $password = '';
69 } elseif (empty($_REQUEST['pma_pw']) || empty($_REQUEST['pma_pw2'])) {
70 $message = PMA_Message::error(__('The password is empty!'));
71 $_error = true;
72 } elseif ($_REQUEST['pma_pw'] != $_REQUEST['pma_pw2']) {
73 $message = PMA_Message::error(__('The passwords aren\'t the same!'));
74 $_error = true;
75 } else {
76 $password = $_REQUEST['pma_pw'];
79 if (! $_error) {
81 // Defines the url to return to in case of error in the sql statement
82 $_url_params = array();
84 $err_url = 'user_password.php' . PMA_generate_common_url($_url_params);
85 if (PMA_isValid($_REQUEST['pw_hash'], 'identical', 'old')) {
86 $hashing_function = 'OLD_PASSWORD';
87 } else {
88 $hashing_function = 'PASSWORD';
91 $sql_query = 'SET password = ' . (($password == '') ? '\'\'' : $hashing_function . '(\'***\')');
92 $local_query = 'SET password = ' . (($password == '') ? '\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($password) . '\')');
93 $result = @PMA_DBI_try_query($local_query)
94 or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, false, $err_url);
96 // Changes password cookie if required
97 // Duration = till the browser is closed for password (we don't want this to be saved)
98 if ($cfg['Server']['auth_type'] == 'cookie') {
99 $GLOBALS['PMA_Config']->setCookie('pmaPass-' . $server,
100 PMA_blowfish_encrypt($password, $GLOBALS['cfg']['blowfish_secret']));
101 } // end if
103 // For http auth. mode, the "back" link will also enforce new
104 // authentication
105 if ($cfg['Server']['auth_type'] == 'http') {
106 $_url_params['old_usr'] = 'relog';
109 // Displays the page
110 require_once './libraries/header.inc.php';
111 echo '<h1>' . __('Change password') . '</h1>' . "\n\n";
112 PMA_showMessage(__('The profile has been updated.'), $sql_query, 'success');
114 <a href="index.php<?php echo PMA_generate_common_url($_url_params); ?>" target="_parent">
115 <strong><?php echo __('Back'); ?></strong></a>
116 <?php
117 require_once './libraries/footer.inc.php';
118 } // end if
119 } // end if
123 * If the "change password" form hasn't been submitted or the values submitted
124 * aren't valid -> displays the form
126 // Loads the headers
127 $GLOBALS['js_include'][] = 'server_privileges.js';
128 require_once './libraries/header.inc.php';
129 echo '<h1>' . __('Change password') . '</h1>' . "\n\n";
131 // Displays an error message if required
132 if (isset($message)) {
133 $message->display();
136 require_once './libraries/display_change_password.lib.php';
139 * Displays the footer
141 require_once './libraries/footer.inc.php';