Issue
I've registered users with the createUserWithEmailAndPassword
method and they are registered on my firebase project (I can see their info). But when I try to login with the created email and password the task.isSuccessful
method is always returning false and the else
statement is running every time.
Code for login and registration:
private Button buttonRegister;
private EditText editTextEmail;
private EditText editTextPassword;
private TextView textViewSignin;
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressDialog=new ProgressDialog(this);
firebaseAuth= FirebaseAuth.getInstance();
buttonRegister = (Button) findViewById(R.id.buttonRegister);
editTextEmail=(EditText) findViewById(R.id.editTextEmail);
editTextPassword=(EditText) findViewById(R.id.editTextPassword);
textViewSignin=(TextView) findViewById(R.id.textViewSignin);
buttonRegister.setOnClickListener(this);
textViewSignin.setOnClickListener(this);
if(firebaseAuth.getCurrentUser()!=null){
//start the profile activity
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
}
private void registerUser(){
String email=editTextEmail.getText().toString().trim();
String password=editTextEmail.getText().toString().trim();
if(TextUtils.isEmpty(email)){
Toast.makeText(this, "Please enter E-mail first", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(password)){
Toast.makeText(this, "Please enter password first", Toast.LENGTH_SHORT).show();
return;
}
progressDialog.setMessage("Registerring User......");
progressDialog.show();
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressDialog.dismiss();
if(task.isSuccessful()){
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
else{
Toast.makeText(MainActivity.this, "Unable to Register! Please try again.", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onClick(View v) {
if(v == buttonRegister){
registerUser();
}
if(v == textViewSignin){
finish();
startActivity(new Intent(this, LoginActivity.class));
}
}
Solution
It was a silly mistake from my side. I assigned email value to password field while registering the user.
String email=editTextEmail.getText().toString().trim();
String password=editTextEmail.getText().toString().trim();
So password was not actually assigned the password which I actually passed. Sorry for this very silly mistake.
Answered By - hemant yadav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.