Translation update done using Pootle.
[phpmyadmin/ammar_yasir.git] / user_password.php
blob9787cc1a4eb8cbf7495756628d8f30bffe835d72
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 $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()
15 * @uses PMA_isValid()
16 * @uses PMA_mysqlDie()
17 * @uses $GLOBALS['PMA_Config']->setCookie()
18 * @uses PMA_blowfish_encrypt()
19 * @uses PMA_showMessage()
20 * @uses define()
21 * @package phpMyAdmin
24 /**
25 * no need for variables importing
26 * @ignore
28 if (! defined('PMA_NO_VARIABLES_IMPORT')) {
29 define('PMA_NO_VARIABLES_IMPORT', true);
32 /**
33 * Gets some core libraries
35 require_once './libraries/common.inc.php';
37 $GLOBALS['js_include'][] = 'server_privileges.js';
39 /**
40 * Displays an error message and exits if the user isn't allowed to use this
41 * script
43 if (!$cfg['ShowChgPassword']) {
44 $cfg['ShowChgPassword'] = PMA_DBI_select_db('mysql');
46 if ($cfg['Server']['auth_type'] == 'config' || !$cfg['ShowChgPassword']) {
47 require_once './libraries/header.inc.php';
48 PMA_Message::error(__('You don\'t have sufficient privileges to be here right now!'))->display();
49 require './libraries/footer.inc.php';
50 } // end if
53 /**
54 * If the "change password" form has been submitted, checks for valid values
55 * and submit the query or logout
57 if (isset($_REQUEST['nopass'])) {
58 // similar logic in server_privileges.php
59 $_error = false;
61 if ($_REQUEST['nopass'] == '1') {
62 $password = '';
63 } elseif (empty($_REQUEST['pma_pw']) || empty($_REQUEST['pma_pw2'])) {
64 $message = PMA_Message::error(__('The password is empty!'));
65 $_error = true;
66 } elseif ($_REQUEST['pma_pw'] != $_REQUEST['pma_pw2']) {
67 $message = PMA_Message::error(__('The passwords aren\'t the same!'));
68 $_error = true;
69 } else {
70 $password = $_REQUEST['pma_pw'];
73 if($GLOBALS['is_ajax_request'] == true && $_error == true) {
74 /**
75 * If in an Ajax request, we don't need to show the rest of the page
77 PMA_ajaxResponse($message, false);
80 if (! $_error) {
82 // Defines the url to return to in case of error in the sql statement
83 $_url_params = array();
85 $err_url = 'user_password.php' . PMA_generate_common_url($_url_params);
86 if (PMA_isValid($_REQUEST['pw_hash'], 'identical', 'old')) {
87 $hashing_function = 'OLD_PASSWORD';
88 } else {
89 $hashing_function = 'PASSWORD';
92 $sql_query = 'SET password = ' . (($password == '') ? '\'\'' : $hashing_function . '(\'***\')');
93 $local_query = 'SET password = ' . (($password == '') ? '\'\'' : $hashing_function . '(\'' . PMA_sqlAddslashes($password) . '\')');
94 $result = @PMA_DBI_try_query($local_query)
95 or PMA_mysqlDie(PMA_DBI_getError(), $sql_query, false, $err_url);
97 // Changes password cookie if required
98 // Duration = till the browser is closed for password (we don't want this to be saved)
99 if ($cfg['Server']['auth_type'] == 'cookie') {
100 $GLOBALS['PMA_Config']->setCookie('pmaPass-' . $server,
101 PMA_blowfish_encrypt($password, $GLOBALS['cfg']['blowfish_secret']));
102 } // end if
104 // For http auth. mode, the "back" link will also enforce new
105 // authentication
106 if ($cfg['Server']['auth_type'] == 'http') {
107 $_url_params['old_usr'] = 'relog';
110 $message = PMA_Message::success(__('The profile has been updated.'));
112 if($GLOBALS['is_ajax_request'] == true) {
113 $extra_data['sql_query'] = PMA_showMessage($message, $sql_query, 'success');
114 PMA_ajaxResponse($message, true, $extra_data);
117 // Displays the page
118 require_once './libraries/header.inc.php';
119 echo '<h1>' . __('Change password') . '</h1>' . "\n\n";
120 PMA_showMessage($message, $sql_query, 'success');
122 <a href="index.php<?php echo PMA_generate_common_url($_url_params); ?>" target="_parent">
123 <strong><?php echo __('Back'); ?></strong></a>
124 <?php
125 require './libraries/footer.inc.php';
126 } // end if
127 } // end if
131 * If the "change password" form hasn't been submitted or the values submitted
132 * aren't valid -> displays the form
134 // Loads the headers
135 require_once './libraries/header.inc.php';
137 echo '<h1>' . __('Change password') . '</h1>' . "\n\n";
139 // Displays an error message if required
140 if (isset($message)) {
141 $message->display();
144 require_once './libraries/display_change_password.lib.php';
147 * Displays the footer
149 require './libraries/footer.inc.php';