错误:我正在尝试使用注册的电子邮件和密码登录,但出现错误, firebase.auth.FirebaseAuthInvalidCredentialsException:密码无效或用户没有密码。
期望:使用注册的电子邮件和密码登录
尝试的解决方案:重新添加了Google服务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 auth 国家听众。 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:失败 com.google.firebase.auth.FirebaseAuthInvalidCredentialsException:密码无效或用户没有密码。 在com.google.firebase.auth.api.internal.zzds.zzb(未知来源) 位于com.google.firebase.auth.api.internal.zzew.zza(未知来源) 在com.google.firebase.auth.api.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, partnership_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();
}
}
});
}
});
答案 0 :(得分: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();
}
}
});
}
希望这对您有所帮助。