• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Can't login after successful registration

Krichukz

Lurker
After user register - everything saves into database correctly but when you try to login with thous details it always fails and returns - false. Couldn't find the issue but might be cause the password is hashed?


Java:
    public class LoginRegister extends AppCompatActivity {

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


        final EditText login_email = (EditText) findViewById(R.id.login_email);
        final EditText login_password = (EditText) findViewById(R.id.login_password);
        final TextView text_register = (TextView) findViewById(R.id.registacijas_poga);

        final Button poga_login= (Button) findViewById(R.id.poga_login);

       text_register.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               Intent text_register_intent = new Intent(LoginRegister.this, activityregister.class);
               LoginRegister.this.startActivity(text_register_intent);
           }
       });

        poga_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String login = login_email.getText().toString();
                final String password = login_password.getText().toString();
                Response.Listener<String> responseListenerL = new Response.Listener<String>(){
                    @Override
                    public void onResponse(String response) {
                        try{
                            JSONObject jsonResponse = new JSONObject(response);
                            boolean success = jsonResponse.getBoolean("success");
                            if (success) {
                                        String name = jsonResponse.getString("name");
                                        String age = jsonResponse.getString("age");
                                        String emails = jsonResponse.getString("email");


                                        Intent intent = new Intent(LoginRegister.this, app.class);

                                intent.putExtra ("name", name);
                                intent.putExtra ("age", age);
                                intent.putExtra ("email", emails);

                                LoginRegister.this.startActivity(intent);
                            }else{
                                AlertDialog.Builder builder = new AlertDialog.Builder(LoginRegister.this);
                                builder.setMessage("Wrong Username or Passowrd!")
                                        .setNegativeButton("Retry", null)
                                        .create()
                                        .show();
                            }
                        }catch (JSONException e){
                            e.printStackTrace();
                        }

                    }
                    };
            LoginRequest loginRequest = new LoginRequest(login, password, responseListenerL);
                RequestQueue Quee = Volley.newRequestQueue(LoginRegister.this);
                Quee.add(loginRequest);
            }
    });}

Code examples in codeshare web:

[Login2.php][1]

[Register2.php ][2]

[LoginRequest.java ][3]

[password.php ][4]


[1]: https://codeshare.io/5Z7ORo
[2]: https://codeshare.io/5DVRMY
[3]: https://codeshare.io/5RWpDo
[4]: https://codeshare.io/GAyRrv
 
A couple of things you can do:

- Put some log statements in your PHP code to output the values of the POST request parameters "email" and "password"

- In your java code put a breakpoint at the following line. Step through the code and examine what's in the returned JSON response data

Code:
JSONObject jsonResponse = new JSONObject(response);
 
Looking at the documentation for password_verify

http://php.net/manual/en/function.password-verify.php

Looks like if you supply the correct plain text password (which you're sending), then the hash should match.
Is there any way you can interactively debug the PHP code?

Hey, thanks for the response! Also Happy New Year.
At the moment I'm looking into way to debug php file other than localhost/login2.php

Had few errors earlier but i fixed them... at the moment all it displays is - {"success":false}
 
It seems that password and email is empty thats why it always shows false.

bool(false) bool(false) {"success":false}
I assume then its my android code fault ?
 
Last edited:
Back
Top Bottom