Login Authentication

0

I would like my code to make the comparison of the email also if it does not exist, but it only does the comparison of the password, how to make the comparison of the two together?

   if (mEmail.equals(email)) {
                if (mPassword.equals(password)) {

                    Intent intent = new Intent(LoginActivity.this, MainActivityListBooks.class);
                    //startActivity(intent);

                    //Intent ii = new Intent(LoginActivity.this, ActivityAttCad.class);
                    intent.putExtra("mId", id1);
                    intent.putExtra("mEmail", email);
                    intent.putExtra("mPassword", password);
                    intent.putExtra("mNick", nickteste);
                    intent.putExtra("mCellphone", cellteste);
                    intent.putExtra("mNome", snome);
                    startActivity(intent);


                    SharedPreferences sharedPreferences = getSharedPreferences("shared_pref_key", Context.MODE_PRIVATE);
                    makeText(LoginActivity.this, "Object stored in SharedPreferences", Toast.LENGTH_LONG);
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putString("id", id1);
                    editor.commit();

                }
                    else {


                        final Toast toast = makeText(getApplicationContext(), "Email ou senha inválido(s)", Toast.LENGTH_SHORT);

                        toast.show();
                        Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                toast.cancel();
                            }
                        }, 500);
                }
                break;
    
asked by anonymous 30.07.2017 / 15:46

1 answer

1

Your code should look like this to work properly:

if (mEmail.equals(email) && (mPassword.equals(password)) {

  Intent intent = new Intent(LoginActivity.this, MainActivityListBooks.class);
  intent.putExtra("mId", id1);
  intent.putExtra("mEmail", email);
  intent.putExtra("mPassword", password);
  intent.putExtra("mNick", nickteste);
  intent.putExtra("mCellphone", cellteste);
  intent.putExtra("mNome", snome);
  startActivity(intent);  

  SharedPreferences sharedPreferences = getSharedPreferences(
    "shared_pref_key", Context.MODE_PRIVATE);
  makeText(LoginActivity.this, "Object stored in SharedPreferences", 
           Toast.LENGTH_LONG);
  SharedPreferences.Editor editor = sharedPreferences.edit();
  editor.putString("id", id1);
  editor.commit();

} else {


    final Toast toast = makeText(getApplicationContext(), 
                                 "Email ou senha inválido(s)", Toast.LENGTH_SHORT);
    toast.show();
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
      toast.cancel();
    }
  }, 500);
}
    
30.07.2017 / 17:32