2

I am trying to set a register and login activity for an Android app with help of volley. i have been able to set up registration page up I have a problem with login activity
as email and password do not get matched with the database . i am using a online server there is a code to my login activity

        package com.gjs.tablepay;

 import android.app.ProgressDialog;
 import android.content.Intent;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.TextView;
import android.widget.Toast;

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.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONArray;
import org.json.JSONObject;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;


public class LoginActivity extends AppCompatActivity {

EditText etxtloginemail,etxtloginpassword;
TextView txtRegister,txtforgotpass;
Button btnlogin;
  PersonBean personbean;

// Is the Request to the Server
StringRequest stringRequest;

// Executes the Request
RequestQueue requestQueue;
ArrayList<PersonBean> personList;
ProgressDialog pd;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    etxtloginemail=(EditText)findViewById(R.id.editTextloginemail);
    etxtloginpassword=(EditText)findViewById(R.id.editTextloginpassword);
    btnlogin=(Button)findViewById(R.id.buttonLogin);
    txtRegister=(TextView)findViewById(R.id.textViewregister);
    txtforgotpass=(TextView)findViewById(R.id.textViewforgotpass);

    personbean = new PersonBean();

    // Initialize Volley's Request Queue
    requestQueue = Volley.newRequestQueue(this);
    pd = new ProgressDialog(this);

    txtRegister.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(LoginActivity.this,RegistrationActivity.class));
        }
    });
    txtforgotpass.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

                startActivity(new Intent(LoginActivity.this,ForgotpassActivity.class));
        }
    });
    btnlogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            init();
        }
    });}

void retrievePerson(){

    pd.show();
    stringRequest = new StringRequest(Request.Method.POST, Util.RETRIEVE_URL,

            // success
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                    pd.dismiss();
                        Toast.makeText(LoginActivity.this,"yo",Toast.LENGTH_LONG).show();

                        if(s.equalsIgnoreCase("success")){
                            Toast.makeText(LoginActivity.this,"yo",Toast.LENGTH_LONG).show();
                            startActivity(new Intent(LoginActivity.this,HomeActivity.class));

                        }else{
                            pd.dismiss();
                            Toast.makeText(LoginActivity.this,"No Person Found",Toast.LENGTH_LONG).show();
                        }

                    }

            },

            // failure
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                   // Toast.makeText(AllPersonsActivity.this,"Some Volley Error", Toast.LENGTH_LONG).show();
                    Log.i("AllPersonsActivity", volleyError.toString());
                    Log.i("AllPersonsActivity",volleyError.getMessage());
                }
            }
    );

    // Execute the StringRequest
    requestQueue.add(stringRequest);

}
    void init(){
          personbean.setEmail(etxtloginemail.getText().toString().trim());
        personbean.setPassword(etxtloginpassword.getText().toString().trim());
        if(personbean.validateLoginPerson()){

            if(Util.isNetworkConnected(this)){

                retrievePerson();

            }else{
                Toast.makeText(this,"Please check your connectivity",Toast.LENGTH_LONG).show();
            }

        }else{
            Toast.makeText(this,"Please Enter Details First",Toast.LENGTH_LONG).show();
        }
    }

}

and here is my login.php

 <?php
$email=$_POST['email'];
$password=$_POST['password'];
include("dbconfig.php");

  $user = @mysql_query("select uid from users where email='$email' and password='$password'");  

 $row = mysql_fetch_array($user,MYSQL_ASSOC);
      $active = $row['active'];
$count = @mysql_num_rows($user);

$response =array();

 if($count==1){
    $response['success']=1;
    $response['message']="Records Retrieved sucessfully";
 }else{
    $response['success']=0;
    $response['message']="Retrieval Failure";
 }
 echo json_encode($response);
?>
4
  • 1
    Please stop using mysql_* functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy. Commented Nov 14, 2016 at 20:36
  • Never store plain text passwords! Please use PHP's built-in functions to handle password security. If you're using a PHP version less than 5.5 you can use the password_hash() compatibility pack. Make sure you don't escape passwords or use any other cleansing mechanism on them before hashing. Doing so changes the password and causes unnecessary additional coding. Commented Nov 14, 2016 at 20:36
  • Little Bobby says your script is at risk for SQL Injection Attacks.. Even escaping the string is not safe! SQL Injection! It's not just for breakfast any more! Commented Nov 14, 2016 at 20:36
  • Have you checked your error logs? You're making an assumption the query is working. Add error reporting to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1); Add error checking, such as or die(mysql_error()) to your queries. Or you can find the issues in your current error logs. Commented Nov 14, 2016 at 20:36

1 Answer 1

1

In your code you are missing getParams() where you specify your variables. It should look like this:

StringRequest request = new StringRequest(Request.Method.POST, insertURL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Log.d("=======", "DEVICE ID SENT");
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("=======", "DEVICE ID ERROR");
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> parameters = new HashMap<>();
            parameters.put("id",userID);
            parameters.put("deviceId", token);
            return parameters;
        }
    };
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.