Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
auth_db.php
001 <?php
002 /**
003 * Database auth plug-in for phpBB3
004 *
005 * Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
006 *
007 * This is for authentication via the integrated user table
008 *
009 * @package login
010 * @version $Id$
011 * @copyright (c) 2005 phpBB Group
012 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
013 *
014 */
015
016 /**
017 * @ignore
018 */
019 if (!defined('IN_PHPBB'))
020 {
021 exit;
022 }
023
024 /**
025 * Login function
026 */
027 function login_db(&$username, &$password)
028 {
029 global $db, $config;
030
031 // do not allow empty password
032 if (!$password)
033 {
034 return array(
035 'status' => LOGIN_BREAK,
036 'error_msg' => 'NO_PASSWORD_SUPPLIED',
037 );
038 }
039
040 $sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts
041 FROM ' . USERS_TABLE . "
042 WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
043 $result = $db->sql_query($sql);
044 $row = $db->sql_fetchrow($result);
045 $db->sql_freeresult($result);
046
047 if (!$row)
048 {
049 return array(
050 'status' => LOGIN_ERROR_USERNAME,
051 'error_msg' => 'LOGIN_ERROR_USERNAME',
052 'user_row' => array('user_id' => ANONYMOUS),
053 );
054 }
055
056 // If there are too much login attempts, we need to check for an confirm image
057 // Every auth module is able to define what to do by itself...
058 if ($config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts'])
059 {
060 $confirm_id = request_var('confirm_id', '');
061 $confirm_code = request_var('confirm_code', '');
062
063 // Visual Confirmation handling
064 if (!$confirm_id)
065 {
066 return array(
067 'status' => LOGIN_ERROR_ATTEMPTS,
068 'error_msg' => 'LOGIN_ERROR_ATTEMPTS',
069 'user_row' => $row,
070 );
071 }
072 else
073 {
074 global $user;
075
076 $sql = 'SELECT code
077 FROM ' . CONFIRM_TABLE . "
078 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
079 AND session_id = '" . $db->sql_escape($user->session_id) . "'
080 AND confirm_type = " . CONFIRM_LOGIN;
081 $result = $db->sql_query($sql);
082 $confirm_row = $db->sql_fetchrow($result);
083 $db->sql_freeresult($result);
084
085 if ($confirm_row)
086 {
087 if (strcasecmp($confirm_row['code'], $confirm_code) === 0)
088 {
089 $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
090 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
091 AND session_id = '" . $db->sql_escape($user->session_id) . "'
092 AND confirm_type = " . CONFIRM_LOGIN;
093 $db->sql_query($sql);
094 }
095 else
096 {
097 return array(
098 'status' => LOGIN_ERROR_ATTEMPTS,
099 'error_msg' => 'CONFIRM_CODE_WRONG',
100 'user_row' => $row,
101 );
102 }
103 }
104 else
105 {
106 return array(
107 'status' => LOGIN_ERROR_ATTEMPTS,
108 'error_msg' => 'CONFIRM_CODE_WRONG',
109 'user_row' => $row,
110 );
111 }
112 }
113 }
114
115 // If the password convert flag is set we need to convert it
116 if ($row['user_pass_convert'])
117 {
118 // in phpBB2 passwords were used exactly as they were sent, with addslashes applied
119 $password_old_format = isset($_REQUEST['password']) ? (string) $_REQUEST['password'] : '';
120 $password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format;
121 $password_new_format = '';
122
123 set_var($password_new_format, stripslashes($password_old_format), 'string');
124
125 if ($password == $password_new_format)
126 {
127 if (!function_exists('utf8_to_cp1252'))
128 {
129 global $phpbb_root_path, $phpEx;
130 include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
131 }
132
133 // cp1252 is phpBB2's default encoding, characters outside ASCII range might work when converted into that encoding
134 if (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password'])
135 {
136 $hash = phpbb_hash($password_new_format);
137
138 // Update the password in the users table to the new format and remove user_pass_convert flag
139 $sql = 'UPDATE ' . USERS_TABLE . '
140 SET user_password = \'' . $db->sql_escape($hash) . '\',
141 user_pass_convert = 0
142 WHERE user_id = ' . $row['user_id'];
143 $db->sql_query($sql);
144
145 $row['user_pass_convert'] = 0;
146 $row['user_password'] = $hash;
147 }
148 else
149 {
150 // Although we weren't able to convert this password we have to
151 // increase login attempt count to make sure this cannot be exploited
152 $sql = 'UPDATE ' . USERS_TABLE . '
153 SET user_login_attempts = user_login_attempts + 1
154 WHERE user_id = ' . $row['user_id'];
155 $db->sql_query($sql);
156
157 return array(
158 'status' => LOGIN_ERROR_PASSWORD_CONVERT,
159 'error_msg' => 'LOGIN_ERROR_PASSWORD_CONVERT',
160 'user_row' => $row,
161 );
162 }
163 }
164 }
165
166 // Check password ...
167 if (!$row['user_pass_convert'] && phpbb_check_hash($password, $row['user_password']))
168 {
169 // Check for old password hash...
170 if (strlen($row['user_password']) == 32)
171 {
172 $hash = phpbb_hash($password);
173
174 // Update the password in the users table to the new format
175 $sql = 'UPDATE ' . USERS_TABLE . "
176 SET user_password = '" . $db->sql_escape($hash) . "',
177 user_pass_convert = 0
178 WHERE user_id = {$row['user_id']}";
179 $db->sql_query($sql);
180
181 $row['user_password'] = $hash;
182 }
183
184 if ($row['user_login_attempts'] != 0)
185 {
186 // Successful, reset login attempts (the user passed all stages)
187 $sql = 'UPDATE ' . USERS_TABLE . '
188 SET user_login_attempts = 0
189 WHERE user_id = ' . $row['user_id'];
190 $db->sql_query($sql);
191 }
192
193 // User inactive...
194 if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
195 {
196 return array(
197 'status' => LOGIN_ERROR_ACTIVE,
198 'error_msg' => 'ACTIVE_ERROR',
199 'user_row' => $row,
200 );
201 }
202
203 // Successful login... set user_login_attempts to zero...
204 return array(
205 'status' => LOGIN_SUCCESS,
206 'error_msg' => false,
207 'user_row' => $row,
208 );
209 }
210
211 // Password incorrect - increase login attempts
212 $sql = 'UPDATE ' . USERS_TABLE . '
213 SET user_login_attempts = user_login_attempts + 1
214 WHERE user_id = ' . $row['user_id'];
215 $db->sql_query($sql);
216
217 // Give status about wrong password...
218 return array(
219 'status' => LOGIN_ERROR_PASSWORD,
220 'error_msg' => 'LOGIN_ERROR_PASSWORD',
221 'user_row' => $row,
222 );
223 }
224
225 ?>