<commit_before>package com.apwglobal.nice.login;

import com.apwglobal.nice.exception.AllegroExecutor;
import com.apwglobal.nice.service.AbstractService;
import com.apwglobal.nice.service.AllegroSession;
import com.apwglobal.nice.service.Configuration;
import com.apwglobal.nice.util.VersionUtil;
import pl.allegro.webapi.DoLoginRequest;
import pl.allegro.webapi.DoLoginResponse;
import pl.allegro.webapi.ServicePort;

public class LoginService extends AbstractService {

    public LoginService(ServicePort allegro, Credentials cred, Configuration conf) {
        super(allegro, cred, conf);
    }

    public AllegroSession login() {
        long version = AllegroExecutor.execute(() -> VersionUtil.getVersion(allegro, conf.getCountryId(), cred.getKey()));

        DoLoginRequest request = new DoLoginRequest(cred.getUsername(), cred.getPassowrd(), conf.getCountryId(), cred.getKey(), version);
        DoLoginResponse response = AllegroExecutor.execute(() -> allegro.doLogin(request));

        return new AllegroSession.Builder()
                .sessionId(response.getSessionHandlePart())
                .userId(response.getUserId())
                .build();
    }
}<commit_msg>- password is now encrypted before transmiting to allegro<commit_after>package com.apwglobal.nice.login;

import com.apwglobal.nice.exception.AllegroExecutor;
import com.apwglobal.nice.service.AbstractService;
import com.apwglobal.nice.service.AllegroSession;
import com.apwglobal.nice.service.Configuration;
import com.apwglobal.nice.util.VersionUtil;
import pl.allegro.webapi.DoLoginEncRequest;
import pl.allegro.webapi.DoLoginEncResponse;
import pl.allegro.webapi.ServicePort;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class LoginService extends AbstractService {

    private static final String SHA_256 = "SHA-256";

    public LoginService(ServicePort allegro, Credentials cred, Configuration conf) {
        super(allegro, cred, conf);
    }

    public AllegroSession login() {
        long version = AllegroExecutor.execute(() -> VersionUtil.getVersion(allegro, conf.getCountryId(), cred.getKey()));

        DoLoginEncRequest request = new DoLoginEncRequest(cred.getUsername(), encPassword(cred.getPassowrd()), conf.getCountryId(), cred.getKey(), version);
        DoLoginEncResponse response = AllegroExecutor.execute(() -> allegro.doLoginEnc(request));

        return new AllegroSession.Builder()
                .sessionId(response.getSessionHandlePart())
                .userId(response.getUserId())
                .build();
    }

    public String encPassword(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance(SHA_256);
            md.update(password.getBytes());
            return Base64.getEncoder().encodeToString(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
{'fraction_non_alphanumeric': 0.10756302521008404, 'fraction_numerical': 0.004369747899159664, 'mean_word_length': 3.8866995073891624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2888525', 'n_tokens_mistral': 848, 'n_tokens_neox': 808, 'n_words': 158}