title: Login authentication using Firebase unsuccessful
body: <p>I'm trying to login with credentials same as I used while registration. Firebase already has entries of registered users. Every time I try to login it displays "Login Unsuccessful" I don't see any problem with the code. Please help.</p>
  
  <pre><code>public class LoginFragment extends Fragment implements View.OnClickListener {
  private EditText email_login, password_login;
  private TextView register_login;
  private Button button_login;
  private FirebaseAuth firebaseAuth;
  private ProgressDialog progressDialog;
  
  public LoginFragment() {
      // Required empty public constructor
  }
  
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View userLoginFragment = inflater.inflate(R.layout.fragment_login, container, false);
  
  
      email_login = (EditText) userLoginFragment.findViewById(R.id.email_login);
      password_login = (EditText) userLoginFragment.findViewById(R.id.password_login);
      register_login = (TextView) userLoginFragment.findViewById(R.id.register_login);
      button_login = (Button) userLoginFragment.findViewById(R.id.button_login);
      progressDialog = new ProgressDialog(this.getActivity());
  
  
      button_login.setOnClickListener(this);
      register_login.setOnClickListener(this);
  
      firebaseAuth = FirebaseAuth.getInstance();
  
      if(firebaseAuth.getCurrentUser()!=null){
          ProfileFragment profileFragment = new ProfileFragment();
          FragmentManager fragmentManager = getFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
          fragmentTransaction.replace(R.id.main_container, profileFragment);
          fragmentTransaction.commit();
      }
  
      return userLoginFragment;
  }
  
  @Override
  public void onClick(View v) {
  
      if (v == button_login)
          userLogin();
  
      if (v == register_login) {
          UserRegisterFragment userRegisterFragment = new UserRegisterFragment();
          FragmentManager fragmentManager = getFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
          fragmentTransaction.replace(R.id.main_container, userRegisterFragment);
          fragmentTransaction.commit();
      }
  
  }//End of onClick() method
  
  public void userLogin(){
      String email = email_login.getText().toString().trim();
      String password = password_login.getText().toString().trim();
  
      if (email.length() == 0) {
          email_login.setError("Username is required");
          email_login.requestFocus();
      }
      if (password.length() == 0) {
          password_login.setError("Password is required");
          password_login.requestFocus();
      }
      if (email.length()&gt;0 &amp;&amp; password.length()&gt;0){
          progressDialog.setMessage("Signing in...");
          progressDialog.show();
          firebaseAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(this.getActivity(), new OnCompleteListener&lt;AuthResult&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                  if (!task.isSuccessful()) {
                      Toast.makeText(LoginFragment.this.getActivity(), "Login unsuccessful!", Toast.LENGTH_SHORT).show();
                      progressDialog.dismiss();
  
                  }
  
                  else{
  
  
                      Toast.makeText(LoginFragment.this.getActivity(), "Login successful!", Toast.LENGTH_SHORT).show();
                      progressDialog.dismiss();
  
                      ProfileFragment profileFragment = new ProfileFragment();
                      FragmentManager fragmentManager = getFragmentManager();
                      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                      fragmentTransaction.replace(R.id.main_container, profileFragment);
                      fragmentTransaction.commit();
                  }
              }
          });
  
      }
  
  }
  }
  </code></pre>