Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->db->sql_return_on_error(true);
     $server_name = $this->install_config->get('server_name');
     $current_time = time();
     $user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
     $user_ip = $user_ip === false ? '' : $user_ip;
     $referer = $this->iohandler->get_server_variable('REFERER');
     // Calculate cookie domain
     $cookie_domain = $server_name;
     if (strpos($cookie_domain, 'www.') === 0) {
         $cookie_domain = substr($cookie_domain, 3);
     }
     // Set default config and post data, this applies to all DB's
     $sql_ary = array('INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('board_startdate', '{$current_time}')", 'INSERT INTO ' . $this->config_table . " (config_name, config_value)\n\t\t\t\tVALUES ('default_lang', '" . $this->db->sql_escape($this->install_config->get('default_lang')) . "')", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('img_imagick')) . "'\n\t\t\t\tWHERE config_name = 'img_imagick'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'\n\t\t\t\tWHERE config_name = 'server_name'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'\n\t\t\t\tWHERE config_name = 'server_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_email'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'\n\t\t\t\tWHERE config_name = 'board_contact'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_domain) . "'\n\t\t\t\tWHERE config_name = 'cookie_domain'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'\n\t\t\t\tWHERE config_name = 'default_dateformat'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'\n\t\t\t\tWHERE config_name = 'email_enable'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'\n\t\t\t\tWHERE config_name = 'smtp_delivery'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'\n\t\t\t\tWHERE config_name = 'smtp_host'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'\n\t\t\t\tWHERE config_name = 'smtp_port'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'\n\t\t\t\tWHERE config_name = 'smtp_auth_method'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'\n\t\t\t\tWHERE config_name = 'smtp_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'\n\t\t\t\tWHERE config_name = 'smtp_password'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'\n\t\t\t\tWHERE config_name = 'cookie_secure'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'\n\t\t\t\tWHERE config_name = 'force_server_vars'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'\n\t\t\t\tWHERE config_name = 'script_path'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'\n\t\t\t\tWHERE config_name = 'server_protocol'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE config_name = 'newest_username'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'avatar_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'plupload_salt'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'\n\t\t\t\tWHERE config_name = 'sitename'", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'\n\t\t\t\tWHERE config_name = 'site_desc'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET username = '******'admin_name')) . "',\n\t\t\t\t\tuser_password='******'admin_passwd')) . "',\n\t\t\t\t\tuser_ip = '" . $this->db->sql_escape($user_ip) . "',\n\t\t\t\t\tuser_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',\n\t\t\t\t\tuser_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',\n\t\t\t\t\tuser_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',\n\t\t\t\t\tuser_email_hash = " . $this->db->sql_escape(phpbb_email_hash($this->install_config->get('board_email'))) . ",\n\t\t\t\t\tusername_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $this->moderator_cache_table . "\n\t\t\t\tSET username = '******'admin_name')) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',\n\t\t\t\ttopic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", 'UPDATE ' . $this->user_table . "\n\t\t\t\tSET user_regdate = {$current_time}", 'UPDATE ' . $this->posts_table . "\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $this->db->sql_escape($user_ip) . "'", 'UPDATE ' . $this->topics_table . "\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", 'UPDATE ' . $this->forums_table . "\n\t\t\t\tSET forum_last_post_time = {$current_time}", 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'\n\t\t\t\tWHERE config_name = 'dbms_version'");
     if (@extension_loaded('gd')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = 'core.captcha.plugins.gd'\n\t\t\t\tWHERE config_name = 'captcha_plugin'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'captcha_gd'";
     }
     $ref = substr($referer, strpos($referer, '://') + 3);
     if (!(stripos($ref, $server_name) === 0)) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'referer_validation'";
     }
     // We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
     $cookie_name = 'phpbb3_';
     $rand_str = md5(mt_rand());
     $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35));
     $rand_str = substr($rand_str, 0, 5);
     $cookie_name .= strtolower($rand_str);
     $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\tSET config_value = '" . $this->db->sql_escape($cookie_name) . "'\n\t\t\tWHERE config_name = 'cookie_name'";
     // Disable avatars if upload directory is not writable
     if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/')) {
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar'";
         $sql_ary[] = 'UPDATE ' . $this->config_table . "\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'allow_avatar_upload'";
     }
     $i = $this->install_config->get('add_config_settings_index', 0);
     $total = sizeof($sql_ary);
     $sql_ary = array_slice($sql_ary, $i);
     foreach ($sql_ary as $sql) {
         if (!$this->db->sql_query($sql)) {
             $error = $this->db->sql_error($this->db->get_sql_error_sql());
             $this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
         }
         $i++;
         // Stop execution if resource limit is reached
         if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0) {
             break;
         }
     }
     if ($i < $total) {
         $this->install_config->set('add_config_settings_index', $i);
         throw new resource_limit_reached_exception();
     }
 }
Ejemplo n.º 2
0
 /**
  * Start with the registration of a new security key.
  * This page should return a name of a template, and
  * it should assign the required variables for this template.
  *
  * @return string
  */
 public function register_start()
 {
     $sql = array();
     for ($i = 0; $i < self::NUMBER_OF_KEYS; $i++) {
         $time = time();
         $key = bin2hex(random_bytes(6));
         $sql[] = array('user_id' => $this->user->data['user_id'], 'valid' => true, 'secret' => $this->password_manager->hash($key), 'registered' => $time);
         $this->template->assign_block_vars('backup', ['KEY' => $key, 'DATE' => $this->user->format_date($time)]);
     }
     $this->db->sql_multi_insert($this->backup_registration_table, $sql);
     return 'tfa_backup_ucp_new';
 }
Ejemplo n.º 3
0
    /**
     * This function generates an array which can be passed to the user_add
     * function in order to create a user
     *
     * @param 	string	$username 	The username of the new user.
     * @param 	string	$password 	The password of the new user.
     * @return 	array 				Contains data that can be passed directly to
     *								the user_add function.
     */
    private function user_row($username, $password)
    {
        // first retrieve default group id
        $sql = 'SELECT group_id
			FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'\n\t\t\t\tAND group_type = " . GROUP_SPECIAL;
        $result = $this->db->sql_query($sql);
        $row = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        if (!$row) {
            trigger_error('NO_GROUP');
        }
        // generate user account data
        return array('username' => $username, 'user_password' => $this->passwords_manager->hash($password), 'user_email' => '', 'group_id' => (int) $row['group_id'], 'user_type' => USER_NORMAL, 'user_ip' => $this->user->ip, 'user_new' => $this->config['new_member_post_limit'] ? 1 : 0);
    }
Ejemplo n.º 4
0
 /**
  * Executes the command user:add
  *
  * Adds a new user to the database. If options are not provided, it will ask for the username, password and email.
  * User is added to the registered user group. Language and timezone default to $config settings.
  *
  * @param InputInterface  $input  The input stream used to get the options
  * @param OutputInterface $output The output stream, used to print messages
  *
  * @return int 0 if all is well, 1 if any errors occurred
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     try {
         $this->validate_user_data();
         $group_id = $this->get_group_id();
     } catch (runtime_exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $user_row = array('username' => $this->data['username'], 'user_password' => $this->password_manager->hash($this->data['new_password']), 'user_email' => $this->data['email'], 'group_id' => $group_id, 'user_timezone' => $this->config['board_timezone'], 'user_lang' => $this->config['default_lang'], 'user_type' => USER_NORMAL, 'user_regdate' => time());
     $user_id = (int) user_add($user_row);
     if (!$user_id) {
         $io->error($this->language->lang('AUTH_NO_PROFILE_CREATED'));
         return 1;
     }
     if ($input->getOption('send-email') && $this->config['email_enable']) {
         $this->send_activation_email($user_id);
     }
     $io->success($this->language->lang('CLI_USER_ADD_SUCCESS', $this->data['username']));
     return 0;
 }
Ejemplo n.º 5
0
    /**
     * {@inheritdoc}
     */
    public function login($username, $password)
    {
        // do not allow empty password
        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));
        }
        if (!@extension_loaded('ldap')) {
            return array('status' => LOGIN_ERROR_EXTERNAL_AUTH, 'error_msg' => 'LDAP_NO_LDAP_EXTENSION', 'user_row' => array('user_id' => ANONYMOUS));
        }
        $this->config['ldap_port'] = (int) $this->config['ldap_port'];
        if ($this->config['ldap_port']) {
            $ldap = @ldap_connect($this->config['ldap_server'], $this->config['ldap_port']);
        } else {
            $ldap = @ldap_connect($this->config['ldap_server']);
        }
        if (!$ldap) {
            return array('status' => LOGIN_ERROR_EXTERNAL_AUTH, 'error_msg' => 'LDAP_NO_SERVER_CONNECTION', 'user_row' => array('user_id' => ANONYMOUS));
        }
        @ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
        @ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
        if ($this->config['ldap_user'] || $this->config['ldap_password']) {
            if (!@ldap_bind($ldap, htmlspecialchars_decode($this->config['ldap_user']), htmlspecialchars_decode($this->config['ldap_password']))) {
                return array('status' => LOGIN_ERROR_EXTERNAL_AUTH, 'error_msg' => 'LDAP_NO_SERVER_CONNECTION', 'user_row' => array('user_id' => ANONYMOUS));
            }
        }
        $search = @ldap_search($ldap, htmlspecialchars_decode($this->config['ldap_base_dn']), $this->ldap_user_filter($username), empty($this->config['ldap_email']) ? array(htmlspecialchars_decode($this->config['ldap_uid'])) : array(htmlspecialchars_decode($this->config['ldap_uid']), htmlspecialchars_decode($this->config['ldap_email'])), 0, 1);
        $ldap_result = @ldap_get_entries($ldap, $search);
        if (is_array($ldap_result) && sizeof($ldap_result) > 1) {
            if (@ldap_bind($ldap, $ldap_result[0]['dn'], htmlspecialchars_decode($password))) {
                @ldap_close($ldap);
                $sql = 'SELECT user_id, username, user_password, user_passchg, user_email, user_type
					FROM ' . USERS_TABLE . "\n\t\t\t\t\tWHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($username)) . "'";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                if ($row) {
                    unset($ldap_result);
                    // User inactive...
                    if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) {
                        return array('status' => LOGIN_ERROR_ACTIVE, 'error_msg' => 'ACTIVE_ERROR', 'user_row' => $row);
                    }
                    // Successful login... set user_login_attempts to zero...
                    return array('status' => LOGIN_SUCCESS, 'error_msg' => false, 'user_row' => $row);
                } else {
                    // retrieve default group id
                    $sql = 'SELECT group_id
						FROM ' . GROUPS_TABLE . "\n\t\t\t\t\t\tWHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'\n\t\t\t\t\t\t\tAND group_type = " . GROUP_SPECIAL;
                    $result = $this->db->sql_query($sql);
                    $row = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    if (!$row) {
                        trigger_error('NO_GROUP');
                    }
                    // generate user account data
                    $ldap_user_row = array('username' => $username, 'user_password' => $this->passwords_manager->hash($password), 'user_email' => !empty($this->config['ldap_email']) ? utf8_htmlspecialchars($ldap_result[0][htmlspecialchars_decode($this->config['ldap_email'])][0]) : '', 'group_id' => (int) $row['group_id'], 'user_type' => USER_NORMAL, 'user_ip' => $this->user->ip, 'user_new' => $this->config['new_member_post_limit'] ? 1 : 0);
                    unset($ldap_result);
                    // this is the user's first login so create an empty profile
                    return array('status' => LOGIN_SUCCESS_CREATE_PROFILE, 'error_msg' => false, 'user_row' => $ldap_user_row);
                }
            } else {
                unset($ldap_result);
                @ldap_close($ldap);
                // Give status about wrong password...
                return array('status' => LOGIN_ERROR_PASSWORD, 'error_msg' => 'LOGIN_ERROR_PASSWORD', 'user_row' => array('user_id' => ANONYMOUS));
            }
        }
        @ldap_close($ldap);
        return array('status' => LOGIN_ERROR_USERNAME, 'error_msg' => 'LOGIN_ERROR_USERNAME', 'user_row' => array('user_id' => ANONYMOUS));
    }
Ejemplo n.º 6
0
Archivo: db.php Proyecto: MrAdder/phpbb
    /**
     * {@inheritdoc}
     */
    public function login($username, $password)
    {
        // Auth plugins get the password untrimmed.
        // For compatibility we trim() here.
        $password = trim($password);
        // do not allow empty password
        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));
        }
        $username_clean = utf8_clean_string($username);
        $sql = 'SELECT *
			FROM ' . USERS_TABLE . "\n\t\t\tWHERE username_clean = '" . $this->db->sql_escape($username_clean) . "'";
        $result = $this->db->sql_query($sql);
        $row = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        if ($this->user->ip && !$this->config['ip_login_limit_use_forwarded'] || $this->user->forwarded_for && $this->config['ip_login_limit_use_forwarded']) {
            $sql = 'SELECT COUNT(*) AS attempts
				FROM ' . LOGIN_ATTEMPT_TABLE . '
				WHERE attempt_time > ' . (time() - (int) $this->config['ip_login_limit_time']);
            if ($this->config['ip_login_limit_use_forwarded']) {
                $sql .= " AND attempt_forwarded_for = '" . $this->db->sql_escape($this->user->forwarded_for) . "'";
            } else {
                $sql .= " AND attempt_ip = '" . $this->db->sql_escape($this->user->ip) . "' ";
            }
            $result = $this->db->sql_query($sql);
            $attempts = (int) $this->db->sql_fetchfield('attempts');
            $this->db->sql_freeresult($result);
            $attempt_data = array('attempt_ip' => $this->user->ip, 'attempt_browser' => trim(substr($this->user->browser, 0, 149)), 'attempt_forwarded_for' => $this->user->forwarded_for, 'attempt_time' => time(), 'user_id' => $row ? (int) $row['user_id'] : 0, 'username' => $username, 'username_clean' => $username_clean);
            $sql = 'INSERT INTO ' . LOGIN_ATTEMPT_TABLE . $this->db->sql_build_array('INSERT', $attempt_data);
            $this->db->sql_query($sql);
        } else {
            $attempts = 0;
        }
        if (!$row) {
            if ($this->config['ip_login_limit_max'] && $attempts >= $this->config['ip_login_limit_max']) {
                return array('status' => LOGIN_ERROR_ATTEMPTS, 'error_msg' => 'LOGIN_ERROR_ATTEMPTS', 'user_row' => array('user_id' => ANONYMOUS));
            }
            return array('status' => LOGIN_ERROR_USERNAME, 'error_msg' => 'LOGIN_ERROR_USERNAME', 'user_row' => array('user_id' => ANONYMOUS));
        }
        $show_captcha = $this->config['max_login_attempts'] && $row['user_login_attempts'] >= $this->config['max_login_attempts'] || $this->config['ip_login_limit_max'] && $attempts >= $this->config['ip_login_limit_max'];
        // If there are too many login attempts, we need to check for a confirm image
        // Every auth module is able to define what to do by itself...
        if ($show_captcha) {
            /* @var $captcha_factory \phpbb\captcha\factory */
            $captcha_factory = $this->phpbb_container->get('captcha.factory');
            $captcha = $captcha_factory->get_instance($this->config['captcha_plugin']);
            $captcha->init(CONFIRM_LOGIN);
            $vc_response = $captcha->validate($row);
            if ($vc_response) {
                return array('status' => LOGIN_ERROR_ATTEMPTS, 'error_msg' => 'LOGIN_ERROR_ATTEMPTS', 'user_row' => $row);
            } else {
                $captcha->reset();
            }
        }
        // Check password ...
        if ($this->passwords_manager->check($password, $row['user_password'], $row)) {
            // Check for old password hash...
            if ($this->passwords_manager->convert_flag || strlen($row['user_password']) == 32) {
                $hash = $this->passwords_manager->hash($password);
                // Update the password in the users table to the new format
                $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\tSET user_password = '******'\n\t\t\t\t\tWHERE user_id = {$row['user_id']}";
                $this->db->sql_query($sql);
                $row['user_password'] = $hash;
            }
            $sql = 'DELETE FROM ' . LOGIN_ATTEMPT_TABLE . '
				WHERE user_id = ' . $row['user_id'];
            $this->db->sql_query($sql);
            if ($row['user_login_attempts'] != 0) {
                // Successful, reset login attempts (the user passed all stages)
                $sql = 'UPDATE ' . USERS_TABLE . '
					SET user_login_attempts = 0
					WHERE user_id = ' . $row['user_id'];
                $this->db->sql_query($sql);
            }
            // User inactive...
            if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE) {
                return array('status' => LOGIN_ERROR_ACTIVE, 'error_msg' => 'ACTIVE_ERROR', 'user_row' => $row);
            }
            // Successful login... set user_login_attempts to zero...
            return array('status' => LOGIN_SUCCESS, 'error_msg' => false, 'user_row' => $row);
        }
        // Password incorrect - increase login attempts
        $sql = 'UPDATE ' . USERS_TABLE . '
			SET user_login_attempts = user_login_attempts + 1
			WHERE user_id = ' . (int) $row['user_id'] . '
				AND user_login_attempts < ' . LOGIN_ATTEMPTS_MAX;
        $this->db->sql_query($sql);
        // Give status about wrong password...
        return array('status' => $show_captcha ? LOGIN_ERROR_ATTEMPTS : LOGIN_ERROR_PASSWORD, 'error_msg' => 'LOGIN_ERROR_PASSWORD', 'user_row' => $row);
    }