0
votes

Error: I am trying to log in with registered email and password but getting an error, firebase.auth.FirebaseAuthInvalidCredentialsException: The password is invalid or the user does not have a password.

Expected: To login with registered email and password

Solutions tried: Re-added google service json file

This is the logs:

03-14 11:24:54.378 16373-16373/com.jaytailor45.fbproject D/FirebaseApp: Notifying auth state listeners. 03-14 11:24:54.378 16373-16373/com.jaytailor45.fbproject D/FirebaseApp: Notified 0 auth state listeners. 03-14 11:25:08.585 16373-16373/com.jaytailor45.fbproject W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@b8c5b14 03-14 11:25:09.414 16373-16373/com.jaytailor45.fbproject W/firebase: signInWithEmail:failure com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The password is invalid or the user does not have a password. at com.google.firebase.auth.api.internal.zzds.zzb(Unknown Source) at com.google.firebase.auth.api.internal.zzew.zza(Unknown Source) at com.google.firebase.auth.api.internal.zzeo.zzc(Unknown Source) at com.google.firebase.auth.api.internal.zzep.onFailure(Unknown Source) at com.google.firebase.auth.api.internal.zzdy.dispatchTransaction(Unknown Source) at com.google.android.gms.internal.firebase_auth.zzb.onTransact(Unknown Source) at android.os.Binder.execTransact(Binder.java:458) 03-14 11:27:14.167 16373-20522/com.jaytailor45.fbproject D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=139692, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-6317095346979771825}]

Code causing the error is given:

l_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String email = l_email.getText().toString();
            final String pass = l_pass.getText().toString();
            mAuth.signInWithEmailAndPassword(email,pass)
                    .addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            Toast.makeText(MainActivity.this,email + pass, Toast.LENGTH_SHORT).show();
                            if (task.isSuccessful()) {
                                Log.d("firebase", "signInWithEmail:success");
                                FirebaseUser user = mAuth.getCurrentUser();
                                startActivity(new Intent(getApplicationContext(),home.class));
                                finish();
                            } else {
                                Log.w("firebase", "signInWithEmail:failure", task.getException());
                                Toast.makeText(getApplicationContext(), "Authentication failed.",Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
        }
    });
1
first you need to create user using createUserWithEmailAndPassword and then if user created successfully only then the user can signin - Santanu Sur
I have already created user Santanu - JayTailor

1 Answers

1
votes

Follow The below Code You Might Get Your Solution.

1) Register Activity.

Call This Function in Button click.

//Entry on firebase-auth
private void register_user(final String display_name, String email, String password) {
    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {

            if (task.isSuccessful()) {
                FirebaseUser current_user = FirebaseAuth.getInstance().getCurrentUser();
                String Uid = current_user.getUid();


                mDatabase = FirebaseDatabase.getInstance().getReference().child("Users")
                        .child(Uid);
                HashMap<String, String> userHashmap = new HashMap<>();

                userHashmap.put("name", display_name);
                userHashmap.put("status", "Hi there! i am using Phoenix ChatApp");
                userHashmap.put("image", "default");
                userHashmap.put("thumb_image", "default");

                // Generating Device Token
                final String curr_user = mAuth.getCurrentUser().getUid();
                final String device_token = FirebaseInstanceId.getInstance().getToken();

                mDatabase.setValue(userHashmap).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            mUserDatabase.child(curr_user).child("devie_token")
                                    .setValue(device_token).addOnSuccessListener(new OnSuccessListener<Void>() {
                                @Override
                                public void onSuccess(Void aVoid) {
                                    mRegProgress.dismiss();
                                    Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
                                    mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                                    startActivity(mainIntent);
                                    finish();

                                }
                            });

                        }
                    }
                });


            } else {
                mRegProgress.hide();
                Toast.makeText(RegisterActivity.this, "Cannot Sign Up,Please Check The Form And Try Again.", Toast.LENGTH_SHORT).show();
            }
        }
    });


}

2)Login Activity

I have Called this function in Click event of login button.


private void login_user(String email, String password) {
        mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {

                if (task.isSuccessful()) {
                    String curr_user = mAuth.getCurrentUser().getUid();
                    String device_token = FirebaseInstanceId.getInstance().getToken();

                    mUserDatabase.child(curr_user).child("devie_token")
                            .setValue(device_token).addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {

                            mLoginProgress.dismiss();
                            Intent mainIntent = new Intent(LoginActivity.this, MainActivity.class);
                            mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(mainIntent);
                            finish();

                        }
                    });


                } else {
                    String error = "";
                    try {
                        throw task.getException();
                    } catch (FirebaseAuthInvalidUserException e) {
                        error = "Invalid Email!";
                    } catch (FirebaseAuthInvalidCredentialsException e) {
                        error = "Invalid Password!";
                    } catch (Exception e) {
                        error = "Default error!";
                        e.printStackTrace();
                    }
                    mLoginProgress.hide();
                    Toast.makeText(LoginActivity.this, error, Toast.LENGTH_LONG).show();

                }
            }
        });
    }

I hope this might help you.