尝试访问基于firebase的登录时出错

问题描述 投票:0回答:1

错误:我尝试使用已注册的电子邮件和密码登录但收到错误,firebase.auth.FirebaseAuthInvalidCredentialsException:密码无效或用户没有密码。

预计:使用注册的电子邮件和密码登录

解决方案尝试:重新添加谷歌服务json文件

这是日志:

03-14 11:24:54.378 16373-16373 / com.jaytailor45.fbproject D / FirebaseApp:通知身份验证状态监听器。 03-14 11:24:54.378 16373-16373 / com.jaytailor45.fbproject D / FirebaseApp:通知0认证状态监听器。 03-14 11:25:08.585 16373-16373 / com.jaytailor45.fbproject W / BiChannelGoogleApi:[FirebaseAuth:] getGoogleApiForMethod()返回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:密码无效或用户没有密码。来自com.google.firebase.auth.api上com.google.firebase.auth.api.internal.zzew.zza(未知来源)的com.google.firebase.auth.api.internal.zzds.zzb(未知来源) .internal.zzeo.zzc(未知来源)com.google.firebase.auth.api.internal.zzep.onFailure(未知来源)com.google.firebase.auth.api.internal.zzdy.dispatchTransaction(未知来源)在com.google.android.gms.internal.firebase_auth.zzb.onTransact(未知来源)android.os.Binder.execTransact(Binder.java:458)03-14 11:27:14.167 16373-20522 / com.jaytailor45 .fbproject D / FA:记录事件(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}]

导致错误的代码给出:

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();
                            }
                        }
                    });
        }
    });
android firebase login firebase-authentication
1个回答
1
投票

按照以下代码,您可能会得到您的解决方案。

1)注册活动。

在按钮单击中调用此函数。

//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)登录活动

我在登录按钮的Click事件中调用了此功能。


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();

                }
            }
        });
    }

我希望这对你有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.