3
* Database auth plug-in for phpBB3
5
* Authentication plug-ins is largely down to Sergey Kanareykin, our thanks to him.
7
* This is for authentication via the integrated user table
10
* @version $Id: auth_db.php,v 1.24 2007/10/05 12:42:06 acydburn Exp $
11
* @copyright (c) 2005 phpBB Group
12
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
19
if (!defined('IN_PHPBB'))
27
function login_db(&$username, &$password)
31
// do not allow empty password
35
'status' => LOGIN_BREAK,
36
'error_msg' => 'NO_PASSWORD_SUPPLIED',
40
$sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts
41
FROM ' . USERS_TABLE . "
42
WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
43
$result = $db->sql_query($sql);
44
$row = $db->sql_fetchrow($result);
45
$db->sql_freeresult($result);
50
'status' => LOGIN_ERROR_USERNAME,
51
'error_msg' => 'LOGIN_ERROR_USERNAME',
52
'user_row' => array('user_id' => ANONYMOUS),
56
// If there are too much login attempts, we need to check for an confirm image
57
// Every auth module is able to define what to do by itself...
58
if ($config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts'])
60
$confirm_id = request_var('confirm_id', '');
61
$confirm_code = request_var('confirm_code', '');
63
// Visual Confirmation handling
67
'status' => LOGIN_ERROR_ATTEMPTS,
68
'error_msg' => 'LOGIN_ERROR_ATTEMPTS',
77
FROM ' . CONFIRM_TABLE . "
78
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
79
AND session_id = '" . $db->sql_escape($user->session_id) . "'
80
AND confirm_type = " . CONFIRM_LOGIN;
81
$result = $db->sql_query($sql);
82
$confirm_row = $db->sql_fetchrow($result);
83
$db->sql_freeresult($result);
87
if (strcasecmp($confirm_row['code'], $confirm_code) === 0)
89
$sql = 'DELETE FROM ' . CONFIRM_TABLE . "
90
WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
91
AND session_id = '" . $db->sql_escape($user->session_id) . "'
92
AND confirm_type = " . CONFIRM_LOGIN;
98
'status' => LOGIN_ERROR_ATTEMPTS,
99
'error_msg' => 'CONFIRM_CODE_WRONG',
107
'status' => LOGIN_ERROR_ATTEMPTS,
108
'error_msg' => 'CONFIRM_CODE_WRONG',
115
// If the password convert flag is set we need to convert it
116
if ($row['user_pass_convert'])
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 = '';
123
set_var($password_new_format, stripslashes($password_old_format), 'string');
125
if ($password == $password_new_format)
127
if (!function_exists('utf8_to_cp1252'))
129
global $phpbb_root_path, $phpEx;
130
include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx);
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'])
136
$hash = phpbb_hash($password_new_format);
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);
145
$row['user_pass_convert'] = 0;
146
$row['user_password'] = $hash;
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);
158
'status' => LOGIN_ERROR_PASSWORD_CONVERT,
159
'error_msg' => 'LOGIN_ERROR_PASSWORD_CONVERT',
166
// Check password ...
167
if (!$row['user_pass_convert'] && phpbb_check_hash($password, $row['user_password']))
169
// Check for old password hash...
170
if (strlen($row['user_password']) == 32)
172
$hash = phpbb_hash($password);
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);
181
$row['user_password'] = $hash;
184
if ($row['user_login_attempts'] != 0)
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);
194
if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
197
'status' => LOGIN_ERROR_ACTIVE,
198
'error_msg' => 'ACTIVE_ERROR',
203
// Successful login... set user_login_attempts to zero...
205
'status' => LOGIN_SUCCESS,
206
'error_msg' => false,
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);
217
// Give status about wrong password...
219
'status' => LOGIN_ERROR_PASSWORD,
220
'error_msg' => 'LOGIN_ERROR_PASSWORD',
b'\\ No newline at end of file'