Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mateusz.kinwsmprojekt;
- import android.widget.EditText;
- import com.android.volley.Request;
- import com.android.volley.RequestQueue;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.toolbox.JsonObjectRequest;
- import com.android.volley.toolbox.StringRequest;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.HashMap;
- import java.util.Map;
- public class DatabaseConnection {
- int isUserExist(final String login, final String password) {
- String fetchUrl = "http://bazadanych14.cba.pl/show.php";
- Response.Listener<JSONObject> random = new Response.Listener<JSONObject>() {
- public int idDatabase;
- public int getIdDatabase() {
- return idDatabase;
- }
- @Override
- public void onResponse(JSONObject response) {
- try{
- JSONArray users = response.getJSONArray("user");
- for (int i = 0; i < users.length();i++) {
- JSONObject user = users.getJSONObject(i);
- String loginDatabase = user.getString("Login");
- String passwordDatabase = user.getString("Password");
- if(login == loginDatabase && password == passwordDatabase){
- idDatabase = user.getInt("ID");
- break;
- }
- else idDatabase = -1;
- }
- }catch(JSONException e) {
- e.printStackTrace();
- }
- }
- };
- JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, fetchUrl,random, new Response.ErrorListener(){
- public void onErrorResponse(VolleyError error) {
- }
- });
- return ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement