<commit_before>package cgeo.geocaching.connector.ec;

import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.R;
import cgeo.geocaching.connector.AbstractLogin;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.network.Network;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.settings.Credentials;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.JsonUtils;
import cgeo.geocaching.utils.Log;

import ch.boye.httpclientandroidlib.HttpResponse;

import com.fasterxml.jackson.databind.JsonNode;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import java.io.IOException;

public class ECLogin extends AbstractLogin {

    private final CgeoApplication app = CgeoApplication.getInstance();
    private String sessionId = null;

    private ECLogin() {
        // singleton
    }

    private static class SingletonHolder {
        @NonNull
        private final static ECLogin INSTANCE = new ECLogin();
    }

    @NonNull
    public static ECLogin getInstance() {
        return SingletonHolder.INSTANCE;
    }

    @Override
    @NonNull
    protected StatusCode login(final boolean retry) {
        final Credentials login = Settings.getCredentials(ECConnector.getInstance());

        if (StringUtils.isEmpty(login.getUsername()) || StringUtils.isEmpty(login.getPassword())) {
            clearLoginInfo();
            Log.e("ECLogin.login: No login information stored");
            return StatusCode.NO_LOGIN_INFO_STORED;
        }

        setActualStatus(app.getString(R.string.init_login_popup_working));

        final Parameters params = new Parameters("user", login.getUsername(), "pass", login.getPassword());
        final HttpResponse loginResponse = Network.postRequest("https://extremcaching.com/exports/apilogin.php", params);

        final String loginData = Network.getResponseData(loginResponse);

        if (StringUtils.isBlank(loginData)) {
            Log.e("ECLogin.login: Failed to retrieve login data");
            return StatusCode.CONNECTION_FAILED_EC; // no login page
        }

        assert loginData != null;
<commit_msg>fix #5409: ECConnector does not check validity of credentials poroperly<commit_after>package cgeo.geocaching.connector.ec;

import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.R;
import cgeo.geocaching.connector.AbstractLogin;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.network.Network;
import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.settings.Credentials;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.JsonUtils;
import cgeo.geocaching.utils.Log;

import ch.boye.httpclientandroidlib.HttpResponse;

import com.fasterxml.jackson.databind.JsonNode;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import java.io.IOException;

public class ECLogin extends AbstractLogin {

    private final CgeoApplication app = CgeoApplication.getInstance();
    private String sessionId = null;

    private ECLogin() {
        // singleton
    }

    private static class SingletonHolder {
        @NonNull
        private final static ECLogin INSTANCE = new ECLogin();
    }

    @NonNull
    public static ECLogin getInstance() {
        return SingletonHolder.INSTANCE;
    }

    @Override
    @NonNull
    protected StatusCode login(final boolean retry) {
        final Credentials login = Settings.getCredentials(ECConnector.getInstance());

        if (login.isInvalid()) {
            clearLoginInfo();
            Log.e("ECLogin.login: No login information stored");
            return StatusCode.NO_LOGIN_INFO_STORED;
        }

        setActualStatus(app.getString(R.string.init_login_popup_working));

        final Parameters params = new Parameters("user", login.getUsername(), "pass", login.getPassword());
        final HttpResponse loginResponse = Network.postRequest("https://extremcaching.com/exports/apilogin.php", params);

        final String loginData = Network.getResponseData(loginResponse);

        if (StringUtils.isBlank(loginData)) {
            Log.e("ECLogin.login: Failed to retrieve login data");
            return StatusCode.CONNECTION_FAILED_EC; // no login page
        }

        assert loginData != null;

{'fraction_non_alphanumeric': 0.09367203447493763, 'fraction_numerical': 0.0013608528010886822, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '365896', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1248, 'n_words': 260}