This repository was archived by the owner on Jan 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathLoginActivity.java
More file actions
130 lines (108 loc) · 4.56 KB
/
LoginActivity.java
File metadata and controls
130 lines (108 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* Copyright 2011 Security Compass
*/
package com.securitycompass.labs.falsesecuremobile;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLException;
import org.json.JSONException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
* Graphical class which allows the user to enter a username and password,
* then perform a login with them.
* @author Ewan Sinclair
*/
public class LoginActivity extends BankingActivity {
/** Useful for avoiding casts when a Context needs to be passed */
private Context mCtx;
/** The button that initiates the login */
private Button mLoginButton;
/** The text field to collect/hold the password. */
private EditText mPasswordField;
/** This application's preferences */
private SharedPreferences mSharedPrefs;
private static final String TAG = "LoginActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCtx = this;
mSharedPrefs = mThisApplication.getSharedPrefs();
checkFirstRun();
setContentView(R.layout.loginactivity);
mLoginButton = (Button) findViewById(R.id.loginscreen_login_button);
mPasswordField = (EditText) findViewById(R.id.loginscreen_password);
mLoginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
performLogin();
}
});
}
/**
* Checks if the application is running for the first time, and sends the user to the
* appropriate setup if it is.
*/
private void checkFirstRun() {
if (mSharedPrefs.getBoolean(BankingApplication.PREF_FIRST_RUN, true)) {
Intent i = new Intent(mCtx, SetServerCredentialsActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
}
}
/** Grabs the username and password and attempts to log in with them */
private void performLogin() {
String password = mPasswordField.getText().toString();
int unlockStatus = RestClient.NO_OP;
try {
unlockStatus = mThisApplication.unlockApplication(password);
} catch (UnsupportedEncodingException e) {
Toast.makeText(mCtx, R.string.error_toast_hasherror, Toast.LENGTH_LONG).show();
Log.e(TAG, e.toString());
} catch (NoSuchAlgorithmException e) {
if (e.toString().matches(".*SSL.*")) {
Toast.makeText(mCtx, R.string.error_ssl_algorithm, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(mCtx, R.string.error_toast_hasherror, Toast.LENGTH_LONG).show();
}
Log.e(TAG, e.toString());
} catch (JSONException e) {
Toast.makeText(mCtx, R.string.error_toast_json_problem, Toast.LENGTH_SHORT).show();
Log.e(TAG, e.toString());
} catch (KeyManagementException e) {
Toast.makeText(mCtx, R.string.error_ssl_keymanagement, Toast.LENGTH_LONG).show();
Log.e(TAG, e.toString());
} catch (SSLException e) {
Toast.makeText(mCtx, R.string.error_ssl_general, Toast.LENGTH_SHORT).show();
Log.e(TAG, e.toString());
} catch (HttpException e) {
Toast.makeText(mCtx, getString(R.string.error_toast_http_error) + e.getStatusCode(), Toast.LENGTH_SHORT).show();
Log.e(TAG, e.toString());
} catch (IOException e) {
Toast.makeText(mCtx, R.string.error_toast_rest_problem, Toast.LENGTH_SHORT).show();
Log.e(TAG, e.toString());
} catch (GeneralSecurityException e) {
Toast.makeText(mCtx, "Crypto failure", Toast.LENGTH_SHORT).show();
Log.e(TAG, e.toString());
}
if (unlockStatus == RestClient.NULL_ERROR) {
Intent launchIntent = new Intent(mCtx, SummaryActivity.class);
launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(launchIntent);
} else {
Toast.makeText(mCtx, R.string.toast_loginfailed, Toast.LENGTH_SHORT).show();
}
}
}