<commit_before>package com.kampr;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import com.forrst.api.ForrstAPI;
import com.forrst.api.ForrstAPIClient;
import com.forrst.api.util.ForrstAuthenticationException;

public class LoginActivity extends Activity {
    
    private final String ACTIVITY_TAG = "LoginActivity";

    protected static final int RESULT_SUCCESS = 1;
    protected static final int RESULT_FAILURE = -1;
    
    private String _loginUsername;
    private String _loginPassword;
    
    private ForrstAPI _forrst;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(ACTIVITY_TAG, "onCreate");

        _forrst = new ForrstAPIClient();
        
        _loginUsername = getIntent().getStringExtra("login_username");
        _loginPassword = getIntent().getStringExtra("login_password");
        
        boolean areCredentialFormatsValid = validateCredentialsFormat(_loginUsername, _loginPassword);
        boolean areCredentialsValid = validateCredentials(_loginUsername, _loginPassword);
        
        if(areCredentialFormatsValid && areCredentialsValid) {
            setResult(RESULT_SUCCESS);
            finish();
        }
        else {
            setResult(RESULT_FAILURE);
            finish();
        }
    }
    
    @Override
    protected void onStart() {
        super.onStart();
        Log.i(ACTIVITY_TAG, "onStart");
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        Log.i(ACTIVITY_TAG, "onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(ACTIVITY_TAG, "onPause");
    }
    
    @Override
    protected void onStop() {
        super.onStop();
        Log.i(ACTIVITY_TAG, "onStop");
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(ACTIVITY_TAG, "onDestroy");
    }
    
    private boolean validateCredentialsFormat(String username, String password) {
        if(username.length() > 0 && password.length() > 0)
            return true;
        else
            return false;
    }
    
    private boolean validateCredentials(String username, String password) {
        JSONObject json = null;
        try {
            json = _forrst.usersAuth(username, password);
            SharedPreferences settings = getSharedPreferences(KamprActivity.KAMPR_APP_PREFS, 0);
            SharedPreferences.Editor editor = settings.edit();
            
            // TODO: save password as a MD5 hash
            editor.putString("login_username", _loginUsername);
            editor.putString("login_password", _loginPassword);
            editor.putString("login_token", json.getString("token"));
            editor.putString("login_user_id", json.getString("user_id"));
            editor.commit();
            return true;
        } catch (ForrstAuthenticationException e) {
            return false;
        } catch (JSONException e) {
            throw new RuntimeException("Error retrieving user data from Forrst authentication", e);
        }
        
    }

}<commit_msg>saving password as a md5 hash<commit_after>package com.kampr;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import com.forrst.api.ForrstAPI;
import com.forrst.api.ForrstAPIClient;
import com.forrst.api.util.ForrstAuthenticationException;

public class LoginActivity extends Activity {
    
    private final String ACTIVITY_TAG = "LoginActivity";

    protected static final int RESULT_SUCCESS = 1;
    protected static final int RESULT_FAILURE = -1;
    
    private String _loginUsername;
    private String _loginPassword;
    
    private ForrstAPI _forrst;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(ACTIVITY_TAG, "onCreate");

        _forrst = new ForrstAPIClient();
        
        _loginUsername = getIntent().getStringExtra("login_username");
        _loginPassword = getIntent().getStringExtra("login_password");
        
        boolean areCredentialFormatsValid = validateCredentialsFormat(_loginUsername, _loginPassword);
        boolean areCredentialsValid = validateCredentials(_loginUsername, _loginPassword);
        
        if(areCredentialFormatsValid && areCredentialsValid) {
            setResult(RESULT_SUCCESS);
            finish();
        }
        else {
            setResult(RESULT_FAILURE);
            finish();
        }
    }
    
    @Override
    protected void onStart() {
        super.onStart();
        Log.i(ACTIVITY_TAG, "onStart");
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        Log.i(ACTIVITY_TAG, "onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.i(ACTIVITY_TAG, "onPause");
    }
    
    @Override
    protected void onStop() {
        super.onStop();
        Log.i(ACTIVITY_TAG, "onStop");
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.i(ACTIVITY_TAG, "onDestroy");
    }
    
    private boolean validateCredentialsFormat(String username, String password) {
        if(username.length() > 0 && password.length() > 0)
            return true;
        else
            return false;
    }
    
    private boolean validateCredentials(String username, String password) {
        JSONObject json = null;
        try {
            json = _forrst.usersAuth(username, password);
            SharedPreferences settings = getSharedPreferences(KamprActivity.KAMPR_APP_PREFS, 0);
            SharedPreferences.Editor editor = settings.edit();

            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] hashedPassword = md.digest(_loginPassword.getBytes());
            
            editor.putString("login_username", _loginUsername);
            editor.putString("login_password", <PASSWORD>());
            editor.putString("login_token", json.getString("token"));
            editor.putString("login_user_id", json.getString("user_id"));
            editor.commit();
            return true;
        } catch (ForrstAuthenticationException e) {
            return false;
        } catch (JSONException e) {
            throw new RuntimeException("Error retrieving user data from Forrst authentication", e);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Error validating user", e);
        }
        
    }

}
{'fraction_non_alphanumeric': 0.09409701928696669, 'fraction_numerical': 0.0018994739918176504, 'mean_word_length': 2.5174717368961974, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '4418680', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1830, 'n_words': 391}