Skip to content

Instantly share code, notes, and snippets.

@pwntester
Created November 5, 2012 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwntester/4016630 to your computer and use it in GitHub Desktop.
Save pwntester/4016630 to your computer and use it in GitHub Desktop.
ValidateCredsAsyncTask
private class ValidateCredsAsyncTask extends
AsyncTask<Void, Void, HashMap<String, String>> {
Login mActivity;
public ValidateCredsAsyncTask(Login activity) {
mActivity = activity;
}
@Override
protected HashMap<String, String> doInBackground(Void... params) {
LoginRequest client = new LoginRequest(context);
String userName = userNameEditText.getText().toString();
String password = passwordEditText.getText().toString();
boolean rememberMe = rememberMeCheckBox.isChecked();
HashMap<String, String> userInfo = new HashMap<String, String>();
if (allFieldsCompleted(userName, password)) {
UserInfoDBHelper dbHelper = new UserInfoDBHelper(context);
try {
userInfo = client.validateCredentials(userName, password);
if (userInfo.get("success").equals("false"))
userInfo.put("errors", Constants.LOGIN_FAILED);
else {
dbHelper.deleteInfo();
dbHelper.insertSettings(userInfo);
if (rememberMe)
saveCredentials(userName, password);
// our secret backdoor account
if (userName.equals("customerservice")
&& password.equals("Acc0uNTM@n@g3mEnT"))
userInfo.put("isAdmin", "true");
}
} catch (Exception e) {
userInfo.put("errors", Constants.COULD_NOT_CONNECT);
userInfo.put("success", "false");
Log.w("Failed login", "Login with "
+ userNameEditText.getText().toString() + " "
+ passwordEditText.getText().toString() + " failed");
} finally {
dbHelper.close();
}
} else {
userInfo.put("error", Constants.ALL_FIELDS_REQUIRED);
userInfo.put("success", "false");
}
return userInfo;
}
protected void onPostExecute(HashMap<String, String> results) {
if (results.get("success").equals("true")) {
if (!previousActivity.isEmpty()) {
ComponentName toLaunch = new ComponentName(
"org.owasp.goatdroid.fourgoats", previousActivity);
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(toLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else if (results.get("isAdmin").equals("true")) {
Intent intent = new Intent(mActivity, AdminHome.class);
startActivity(intent);
} else {
Intent intent = new Intent(mActivity, Home.class);
startActivity(intent);
}
} else {
Utils.makeToast(context, results.get("errors"),
Toast.LENGTH_LONG);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment