Advertisement
Guest User

Untitled

a guest
Nov 13th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. package com.tiongson.camille.threatmapping;
  2.  
  3. import android.app.Activity;
  4. import android.app.ProgressDialog;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.os.AsyncTask;
  8. import android.support.v7.app.ActionBar;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.view.View;
  15. import android.widget.Toast;
  16.  
  17. import org.json.JSONObject;
  18.  
  19. import java.util.ArrayList;
  20. import java.util.HashMap;
  21.  
  22. public class login extends Activity {
  23.  
  24. Button btnLogIn;
  25. Intent intent;
  26. JSONObject jsonobject;
  27.  
  28. Button btnSignUp;
  29. EditText txtUsername, txtPassword;
  30.  
  31. @Override
  32. protected void onCreate(Bundle savedInstanceState) {
  33. super.onCreate(savedInstanceState);
  34. setContentView(R.layout.activity_login);
  35.  
  36. btnLogIn = (Button)findViewById(R.id.btnLogIn);
  37. btnSignUp = (Button)findViewById(R.id.btnSignUp);
  38. txtUsername = (EditText)findViewById(R.id.txtliusername);
  39. txtPassword = (EditText)findViewById(R.id.txtlipassword);
  40.  
  41. // jsonobject = JSONfunctions.getJSONfromURL("http://sql18.hostinger.ph/phpmyadmin/index.php?db=u897407316_tret&lang=en&token=6afd355a23affd65cb4d05f814cc7921&phpMyAdmin=e2ba129883c7c52bc7e30fb543d3fa1095372c90");
  42. }
  43. public void gosignup(View view){
  44. intent = new Intent(this, SignUp.class);
  45. startActivity(intent);
  46. }
  47. public void gologin(View view){
  48. String name = txtUsername.getText().toString();
  49. String pw = txtPassword.getText().toString();
  50. String type = "login";
  51.  
  52. if((name.trim().equals(""))||pw.trim().equals("")){
  53. Toast.makeText(getApplicationContext(), "Please fill up all information", Toast.LENGTH_LONG).show();
  54. }
  55. else {
  56.  
  57. Toast.makeText(this, "Logging in...", Toast.LENGTH_SHORT).show();
  58. new LogInAction(this).execute(name, pw);
  59.  
  60. // intent = new Intent(this, UserHomeDrawer.class);
  61. //startActivity(intent);
  62. }
  63. }
  64.  
  65. }
  66.  
  67. package com.tiongson.camille.threatmapping;
  68.  
  69. import android.content.Context;
  70. import android.content.Intent;
  71. import android.os.AsyncTask;
  72. import android.util.Log;
  73. import android.widget.Toast;
  74.  
  75. import org.json.JSONException;
  76. import org.json.JSONObject;
  77.  
  78. import java.io.BufferedReader;
  79. import java.io.IOException;
  80. import java.io.InputStreamReader;
  81. import java.io.UnsupportedEncodingException;
  82. import java.net.HttpURLConnection;
  83. import java.net.MalformedURLException;
  84. import java.net.URL;
  85. import java.net.URLEncoder;
  86.  
  87. /**
  88. * Created by Camille on 11/13/2016.
  89. */
  90.  
  91. public class LogInAction extends AsyncTask<String, Void, String> {
  92. private Context context;
  93.  
  94. public LogInAction(Context context) {
  95. this.context = context;
  96. }
  97.  
  98. protected void onPreExecute() {
  99.  
  100. }
  101. @Override
  102. protected String doInBackground(String... arg0) {
  103. String username = arg0[0];
  104. String password = arg0[1];
  105.  
  106. String link;
  107. String data;
  108. BufferedReader bufferedReader;
  109. String result;
  110.  
  111. try {
  112. data = "?username=" + URLEncoder.encode(username, "UTF-8");
  113. data += "&password=" + URLEncoder.encode(password, "UTF-8");
  114.  
  115. link = "http://threatmam.esy.es/loginActionAndroid.php" + data;
  116. URL url = new URL(link);
  117. HttpURLConnection con = (HttpURLConnection) url.openConnection();
  118.  
  119. bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
  120. result = bufferedReader.readLine();
  121. return result;
  122.  
  123. } catch (Exception e) {
  124. return new String("Exception: " + e.getMessage());
  125. }
  126.  
  127. }
  128.  
  129. @Override
  130. protected void onPostExecute(String result) {
  131. String jsonStr = result.toString();
  132. if (jsonStr != null) {
  133. try {
  134. JSONObject jsonObj = new JSONObject(jsonStr);
  135. // JSONObject jsonObj = new JSONObject(jsonStr.substring(jsonStr.indexOf("{"), jsonStr.lastIndexOf("}") + 1));
  136. String query_result = jsonObj.getString("query_result");
  137. if (query_result.equals("SUCCESS")) {
  138. Toast.makeText(context, "Log in successful!", Toast.LENGTH_SHORT).show();
  139. Intent intent = new Intent(context,UserHomeDrawer.class)
  140. .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  141. context.startActivity(intent);
  142. } else if (query_result.equals("FAILURE")) {
  143. Toast.makeText(context, "Log in failed.", Toast.LENGTH_SHORT).show();
  144. } else {
  145. Toast.makeText(context, "Couldn't connect to remote database.", Toast.LENGTH_SHORT).show();
  146. }
  147. } catch (JSONException e) {
  148. e.printStackTrace();
  149. Log.d("JSON", "Error:",e);
  150. Toast.makeText(context, ""+e+"RES: "+jsonStr, Toast.LENGTH_SHORT).show();
  151. }
  152. } else {
  153. Toast.makeText(context, "Couldn't get any JSON data.", Toast.LENGTH_SHORT).show();
  154. }
  155. }
  156. }
  157.  
  158. <?php
  159. $un = $_GET['username'];
  160. $pw = md5(sha1($_GET['password']));
  161.  
  162. $res=0;
  163. include "connect.php";
  164.  
  165.  
  166. $query = "SELECT * FROM tbl_mobileuser";
  167. result = $mysqli->query($query);
  168. if ($result->num_rows > 0) {
  169. while($row = $result->fetch_assoc()) {
  170. if(($un == $row['Username']) && if($pw == $row['Password'])){
  171. echo '{"query_result":"SUCCESS"}';
  172. $res = 1;
  173. }
  174. }
  175. }
  176. else{
  177. echo '{"query_result":"FAILURE"}';
  178. }
  179.  
  180.  
  181. if($res == 0){
  182. echo '{"query_result":"FAILURE"}';
  183. }
  184. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement