Check if this letter exists

Is there a way to find out if a user-entered message in Firebase really is? Does the email and password method have a built-in signature?

EDIT: sorry for the misunderstanding. I don’t care if an email has been used before, what I need to know: if the email entered is “composed” or “real, exists”

+7
source share
4 answers

Yes, you can do this either to create a new account or to log in to it:

To create, read createUserWithEmailAndPassword Docs

createUserWithEmailAndPassword throws 3 exceptions:

  • FirebaseAuthWeakPasswordException : if the password is not strong enough
  • FirebaseAuthInvalidCredentialsException : if the email address is incorrect

  • FirebaseAuthUserCollisionException : if an account already exists with the specified email address .

You can handle this in onCompleteListener or onFailureListener

Here's an example where mAuth is a 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()); } } } } ); 

To log in, first read signInWithEmailAndPassword Docs .

signInWithEmailAndPassword throws two exceptions:

  • FirebaseAuthInvalidUserException : if the message does not exist or is disabled.
  • FirebaseAuthInvalidCredentialsException : if password is incorrect

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()); } } } } ); 
+19
source

Perhaps this is a late answer, but only for someone who passed by, can get an answer. I think the best way to check if an email exists or not is to send a confirmation email to the opening email.

Try checking out this link.

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

Firebase provided a really easy way to check a user's email.

0
source

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

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

Then, as Jin Liu suggests, use sendEmailVerification (), for example:

  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(); } } } }); 
0
source

There is another solution without any user creation or process entry.

 //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!"); } } }); 
0
source

All Articles