| <?php |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| if (!defined('IN_PHPBB')) |
| { |
| exit; |
| } |
| |
| |
| |
| |
| function login_db(&$username, &$password) |
| { |
| global $db, $config; |
| |
| |
| if (!$password) |
| { |
| return array( |
| 'status' => LOGIN_ERROR_PASSWORD, |
| 'error_msg' => 'NO_PASSWORD_SUPPLIED', |
| 'user_row' => array('user_id' => ANONYMOUS), |
| ); |
| } |
| |
| if (!$username) |
| { |
| return array( |
| 'status' => LOGIN_ERROR_USERNAME, |
| 'error_msg' => 'LOGIN_ERROR_USERNAME', |
| 'user_row' => array('user_id' => ANONYMOUS), |
| ); |
| } |
| |
| $sql = 'SELECT user_id, username, user_password, user_passchg, user_pass_convert, user_email, user_type, user_login_attempts |
| FROM ' . USERS_TABLE . " |
| WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; |
| $result = $db->sql_query($sql); |
| $row = $db->sql_fetchrow($result); |
| $db->sql_freeresult($result); |
| |
| if (!$row) |
| { |
| return array( |
| 'status' => LOGIN_ERROR_USERNAME, |
| 'error_msg' => 'LOGIN_ERROR_USERNAME', |
| 'user_row' => array('user_id' => ANONYMOUS), |
| ); |
| } |
| |
| |
| |
| if ($config['max_login_attempts'] && $row['user_login_attempts'] >= $config['max_login_attempts']) |
| { |
| $confirm_id = request_var('confirm_id', ''); |
| $confirm_code = request_var('confirm_code', ''); |
| |
| |
| if (!$confirm_id) |
| { |
| return array( |
| 'status' => LOGIN_ERROR_ATTEMPTS, |
| 'error_msg' => 'LOGIN_ERROR_ATTEMPTS', |
| 'user_row' => $row, |
| ); |
| } |
| else |
| { |
| global $user; |
| |
| $sql = 'SELECT code |
| FROM ' . CONFIRM_TABLE . " |
| WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "' |
| AND session_id = '" . $db->sql_escape($user->session_id) . "' |
| AND confirm_type = " . CONFIRM_LOGIN; |
| $result = $db->sql_query($sql); |
| $confirm_row = $db->sql_fetchrow($result); |
| $db->sql_freeresult($result); |
| |
| if ($confirm_row) |
| { |
| if (strcasecmp($confirm_row['code'], $confirm_code) === 0) |
| { |
| $sql = 'DELETE FROM ' . CONFIRM_TABLE . " |
| WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "' |
| AND session_id = '" . $db->sql_escape($user->session_id) . "' |
| AND confirm_type = " . CONFIRM_LOGIN; |
| $db->sql_query($sql); |
| } |
| else |
| { |
| return array( |
| 'status' => LOGIN_ERROR_ATTEMPTS, |
| 'error_msg' => 'CONFIRM_CODE_WRONG', |
| 'user_row' => $row, |
| ); |
| } |
| } |
| else |
| { |
| return array( |
| 'status' => LOGIN_ERROR_ATTEMPTS, |
| 'error_msg' => 'CONFIRM_CODE_WRONG', |
| 'user_row' => $row, |
| ); |
| } |
| } |
| } |
| |
| |
| if ($row['user_pass_convert']) |
| { |
| |
| $password_old_format = isset($_REQUEST['password']) ? (string) $_REQUEST['password'] : ''; |
| $password_old_format = (!STRIP) ? addslashes($password_old_format) : $password_old_format; |
| $password_new_format = ''; |
| |
| set_var($password_new_format, stripslashes($password_old_format), 'string'); |
| |
| if ($password == $password_new_format) |
| { |
| if (!function_exists('utf8_to_cp1252')) |
| { |
| global $phpbb_root_path, $phpEx; |
| include($phpbb_root_path . 'includes/utf/data/recode_basic.' . $phpEx); |
| } |
| |
| |
| if (md5($password_old_format) == $row['user_password'] || md5(utf8_to_cp1252($password_old_format)) == $row['user_password']) |
| { |
| $hash = phpbb_hash($password_new_format); |
| |
| |
| $sql = 'UPDATE ' . USERS_TABLE . ' |
| SET user_password = \'' . $db->sql_escape($hash) . '\', |
| user_pass_convert = 0 |
| WHERE user_id = ' . $row['user_id']; |
| $db->sql_query($sql); |
| |
| $row['user_pass_convert'] = 0; |
| $row['user_password'] = $hash; |
| } |
| else |
| { |
| |
| |
| $sql = 'UPDATE ' . USERS_TABLE . ' |
| SET user_login_attempts = user_login_attempts + 1 |
| WHERE user_id = ' . $row['user_id']; |
| $db->sql_query($sql); |
| |
| return array( |
| 'status' => LOGIN_ERROR_PASSWORD_CONVERT, |
| 'error_msg' => 'LOGIN_ERROR_PASSWORD_CONVERT', |
| 'user_row' => $row, |
| ); |
| } |
| } |
| } |
| |
| |
| if (!$row['user_pass_convert'] && phpbb_check_hash($password, $row['user_password'])) |
| { |
| |
| if (strlen($row['user_password']) == 32) |
| { |
| $hash = phpbb_hash($password); |
| |
| |
| $sql = 'UPDATE ' . USERS_TABLE . " |
| SET user_password = '" . $db->sql_escape($hash) . "', |
| user_pass_convert = 0 |
| WHERE user_id = {$row['user_id']}"; |
| $db->sql_query($sql); |
| |
| $row['user_password'] = $hash; |
| } |
| |
| if ($row['user_login_attempts'] != 0) |
| { |
| |
| $sql = 'UPDATE ' . USERS_TABLE . ' |
| SET user_login_attempts = 0 |
| WHERE user_id = ' . $row['user_id']; |
| $db->sql_query($sql); |
| } |
| |
| |
| if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) |
| { |
| return array( |
| 'status' => LOGIN_ERROR_ACTIVE, |
| 'error_msg' => 'ACTIVE_ERROR', |
| 'user_row' => $row, |
| ); |
| } |
| |
| |
| return array( |
| 'status' => LOGIN_SUCCESS, |
| 'error_msg' => false, |
| 'user_row' => $row, |
| ); |
| } |
| |
| |
| $sql = 'UPDATE ' . USERS_TABLE . ' |
| SET user_login_attempts = user_login_attempts + 1 |
| WHERE user_id = ' . $row['user_id']; |
| $db->sql_query($sql); |
| |
| |
| return array( |
| 'status' => LOGIN_ERROR_PASSWORD, |
| 'error_msg' => 'LOGIN_ERROR_PASSWORD', |
| 'user_row' => $row, |
| ); |
| } |
| |
| ?> |