Trying to set confirm password with firebase auth

Viewed 4369

I'm trying to program my first app and I'm using firebase auth email-password as my login method. On my sign up activity I want to have email, password and confirm password. I can't make the app check if password >= 6 characters and if password and confirm password are equals before the account is created. The app seems to check if password >= 6 but if thats true it creates the account without checking if password = confirm password. I also would like to display an error message saying that the username is already being used.

Here is my code

    private void signUpUser(String email, final String password) {
    auth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (!task.isSuccessful())
                    {
                        if (password.length() < 6)
                            snackbar = Snackbar.make(activity_criar_conta, "Your password must have at least 6 characters.", Snackbar.LENGTH_SHORT);
                                    snackbar.show();

                        String pass2 = etConfirmarSenha.getText().toString();

                        if (!password.equals(pass2))
                        snackbar = Snackbar.make(activity_criar_conta, "Both password fields must be identic", Snackbar.LENGTH_SHORT);
                        snackbar.show();

                    }
                    else{
                        String emailuser = etCriarEmail.getText().toString();
                        snackbar = Snackbar.make(activity_criar_conta, "Your account was created with sucess: "+emailuser,Snackbar.LENGTH_SHORT);
                        snackbar.show();
1 Answers
Related