I just wrote this password and password confirmation validation code function that checks to see if a password is empty or not, and is it match (password = confirmPassword). I'm not sure this is the best way to do it, but for now it dont works really well.
private void checkDataEntered()
{
if(isEmpty(RegisterFirstName))
{
RegisterFirstName.setError("You must enter first name to register");
}
if(isEmpty(RegisterLastName))
{
RegisterLastName.setError("Last name is required");
}
if(isEmail(RegisterEmail) == false)
{
RegisterEmail.setError("Enter your valid email.");
}
if(isEmpty(RegisterPassword))
{
RegisterPassword.setError("Enter your password.");
}
if(isEmpty(RegisterConfirmPassword))
{
RegisterConfirmPassword.setError("Enter your confirmation password");
if (!RegisterConfirmPassword.equals(RegisterPassword))
{
Toast.makeText(Signup.this, "Password do not match", Toast.LENGTH_SHORT).show();
}
}
else
{
loadingBar.setTitle("Creating New Account");
loadingBar.setMessage("Please wait while we are creating account for you.");
loadingBar.show();
String email = null;
String password = null;
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>()
{
@Override
public void onComplete(@NonNull Task<AuthResult> task)
{
if(task.isSuccessful())
{
Toast.makeText(Signup.this, "You have successfully signed up", Toast.LENGTH_SHORT).show();
Intent mainIntent = new Intent(Signup.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
finish();
}
else
{
Toast.makeText(Signup.this, "Error occured, please try again.", Toast.LENGTH_SHORT).show();
}
loadingBar.dismiss();
}
});
}
}
mAuth.createUserWithEmailAndPassword(email, password)
is suspicious, because at that pointemail
andpassword
are bothnull
. I don't see how thetask
in theonComplete
callback can be successful. \$\endgroup\$