Check if given email exists

Is there a way to know if the email entered by user is real in Firebase? Does the built-in sign up with email&password method have this feature?

EDIT: sorry for the misunderstanding . I don't care if the email has been used before , what I need to know is: if the entered email is 'made-up' or 'real , exists'

Answers


Yes, you can do that either you create new account or signing in:

For creating, read createUserWithEmailAndPassword's Docs

createUserWithEmailAndPassword throws 3 exceptions:

  1. FirebaseAuthWeakPasswordException: if the password is not strong enough
  2. FirebaseAuthInvalidCredentialsException: if the email address is malformed

  3. FirebaseAuthUserCollisionException: if there already exists an account with the given email address.

You can handle that in onCompleteListener or onFailureListener

Here an example where mAuth is FirebaseAuth instance:

mAuth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(
                    new OnCompleteListener<AuthResult>()
                    {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task)
                        {
                            if (!task.isSuccessful())
                            {
                                try
                                {
                                    throw task.getException();
                                }
                                // if user enters wrong email.
                                catch (FirebaseAuthWeakPasswordException weakPassword)
                                {
                                    Log.d(TAG, "onComplete: weak_password");

                                    // TODO: take your actions!
                                }
                                // if user enters wrong password.
                                catch (FirebaseAuthInvalidCredentialsException malformedEmail)
                                {
                                    Log.d(TAG, "onComplete: malformed_email");

                                    // TODO: Take your action
                                }
                                catch (FirebaseAuthUserCollisionException existEmail)
                                {
                                    Log.d(TAG, "onComplete: exist_email");

                                    // TODO: Take your action
                                }
                                catch (Exception e)
                                {
                                    Log.d(TAG, "onComplete: " + e.getMessage());
                                }
                            }
                        }
                    }
            );

For signing in, read signInWithEmailAndPassword's Docs first.

signInWithEmailAndPassword throws two exceptions:

  1. FirebaseAuthInvalidUserException: if email doesn't exist or disabled.
  2. FirebaseAuthInvalidCredentialsException: if password is wrong

Here is an example:

mAuth.signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(
                    new OnCompleteListener<AuthResult>()
                    {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task)
                        {
                            if (!task.isSuccessful())
                            {
                                try
                                {
                                    throw task.getException();
                                }
                                // if user enters wrong email.
                                catch (FirebaseAuthInvalidUserException invalidEmail)
                                {
                                    Log.d(TAG, "onComplete: invalid_email");

                                    // TODO: take your actions!
                                }
                                // if user enters wrong password.
                                catch (FirebaseAuthInvalidCredentialsException wrongPassword)
                                {
                                    Log.d(TAG, "onComplete: wrong_password");

                                    // TODO: Take your action
                                }
                                catch (Exception e)
                                {
                                    Log.d(TAG, "onComplete: " + e.getMessage());
                                }
                            }
                        }
                    }
            );

This maybe late answer but just for someone passing by could get benefit from the answer. I think the best way to check if the email is exist or not is to send the verification email to the inputing email.

Try checking out this link

https://firebase.googleblog.com/2017/02/email-verification-in-firebase-auth.html

Firebase has provided really easy way to verify user email.


It would be almost impossible to check if the email entered exists, you can however check if the email string entered conforms to the valid email structure:

if(!isValidEmail(etEmail.getText().toString())) {
         Toast.makeText(getActivity(), "Invalid input for email", Toast.LENGTH_LONG).show();

Then like Jin Liu suggests, use the sendEmailVerification(), like:

 mFirebaseUser.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if(task.isSuccessful())
                Toast.makeText(getContext(), "Email Verfication Sent", Toast.LENGTH_LONG).show();
                else {
                    try{
                        throw task.getException();
                    }catch (Exception e) {

                        Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                    }

                }
            }
        });

There is another solution without any create user or sign in processes.

//check email already exist or not.
    firebaseAuth.fetchSignInMethodsForEmail(email)
            .addOnCompleteListener(new OnCompleteListener<SignInMethodQueryResult>() {
                @Override
                public void onComplete(@NonNull Task<SignInMethodQueryResult> task) {

                    boolean isNewUser = task.getResult().getSignInMethods().isEmpty();

                    if (isNewUser) {
                        Log.e("TAG", "Is New User!");
                    } else {
                        Log.e("TAG", "Is Old User!");
                    }

                }
            });

Need Your Help

Is there a pure CSS way to make an input transparent?

html css

How can I make this input transparent?

Vectorised Haversine formula with a pandas dataframe

python pandas haversine

I know that to find the distance between two latitude, longitude points I need to use the haversine function: