Advertisement
Guest User

Untitled

a guest
Apr 9th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. package com.mateusz.kinwsmprojekt;
  2.  
  3.  
  4. import android.widget.EditText;
  5.  
  6. import com.android.volley.Request;
  7. import com.android.volley.RequestQueue;
  8. import com.android.volley.Response;
  9. import com.android.volley.VolleyError;
  10. import com.android.volley.toolbox.JsonObjectRequest;
  11. import com.android.volley.toolbox.StringRequest;
  12.  
  13. import org.json.JSONArray;
  14. import org.json.JSONException;
  15. import org.json.JSONObject;
  16.  
  17. import java.util.HashMap;
  18. import java.util.Map;
  19.  
  20. public class DatabaseConnection {
  21.  
  22.  
  23.  
  24. int isUserExist(final String login, final String password) {
  25.  
  26. String fetchUrl = "http://bazadanych14.cba.pl/show.php";
  27.  
  28. Response.Listener<JSONObject> random = new Response.Listener<JSONObject>() {
  29. public int idDatabase;
  30.  
  31. public int getIdDatabase() {
  32. return idDatabase;
  33. }
  34.  
  35.  
  36.  
  37. @Override
  38. public void onResponse(JSONObject response) {
  39. try{
  40.  
  41. JSONArray users = response.getJSONArray("user");
  42. for (int i = 0; i < users.length();i++) {
  43. JSONObject user = users.getJSONObject(i);
  44.  
  45. String loginDatabase = user.getString("Login");
  46. String passwordDatabase = user.getString("Password");
  47.  
  48.  
  49. if(login == loginDatabase && password == passwordDatabase){
  50. idDatabase = user.getInt("ID");
  51. break;
  52. }
  53. else idDatabase = -1;
  54.  
  55. }
  56.  
  57. }catch(JSONException e) {
  58. e.printStackTrace();
  59. }
  60.  
  61. }
  62.  
  63.  
  64. };
  65.  
  66.  
  67. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, fetchUrl,random, new Response.ErrorListener(){
  68.  
  69. public void onErrorResponse(VolleyError error) {
  70. }
  71.  
  72. });
  73.  
  74. return ;
  75.  
  76.  
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement