检查是否存在电子邮件 [英] Check if given email exists
问题描述
编辑:抱歉的误解。我不在乎以前是否使用过电子邮件,我需要知道的是:如果输入的电子邮件是制造或真实的,存在的
创建时请阅读 createUserWithEmailAndPassword
的 Docs
这里是一个例子,其中 createUserWithEmailAndPassword
throws 3例外:
$ b
FirebaseAuthWeakPasswordException
:如果密码不够好
FirebaseAuthInvalidCredentialsException
:如果电子邮件地址格式不正确
您可以在 onCompleteListener
或 onFailureListener
/ p>
mAuth
是 FirebaseAuth
实例:
mAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener($ b $ new OnCompleteListener< AuthResult>()
{
@Override
public void onComplete(@NonNull Task< AuthResult>任务)
{
if(!task.isSuccessful())
{
try
{
throw task.getException();
}
//如果用户输入错误的电子邮件地址
catch(FirebaseAuthWeakPasswordException weakPassword)
{
Log.d(TAG,onComplete:weak_password);
// TODO:采取行动!
}
//如果用户输入错误的密码。
catch(FirebaseAuthInvalidCredentialsException malformedEmail)
{
Log.d(TAG,onComplete:malformed_email);
$ b // TODO:执行您的操作
catch(FirebaseAuthUserCollisionException existEmail)
{
Log.d(TAG,onComplete:exist_email) ;
$ b $ // TODO:执行你的操作
catch(Exception e)
{
Log.d(TAG,onComplete:+ e .getMessage());
}
}
}
}
);
要登录,请阅读 signInWithEmailAndPassword
的文档。
$ b
signInWithEmailAndPassword
抛出两个例外:
-
FirebaseAuthInvalidUserException
:如果电子邮件不存在或不被禁用。 c $ c>:如果密码不正确
这是一个例子:
<
.addOnCompleteListener(
)OnCompleteListener< AuthResult>()
{
@Override $ b $ mAb.signInWithEmailAndPassword(email,password)
> $ b public void onComplete(@NonNull Task< AuthResult> task)
{
if(!task.isSuccessful())
{
try
{
抛出task.getException();
}
//如果用户输入错误的电子邮件
catch(FirebaseAuthInvalidUserException invalidEmail)
{
Log.d(TAG,onComplete:invalid_email);
// TODO:采取行动!
}
//如果用户输入错误的密码。
catch(FirebaseAuthInvalidCredentialsException wrongPassword)
{
Log.d(TAG,onComplete:wrong_password);
$ b $ // TODO:执行你的操作
catch(Exception e)
{
Log.d(TAG,onComplete:+ e .getMessage());
}
}
}
}
);
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'
Yes, you can do that either you create new account or signing in:
For creating, read createUserWithEmailAndPassword
's Docs
createUserWithEmailAndPassword
throws 3 exceptions:
FirebaseAuthWeakPasswordException
: if the password is not strong enoughFirebaseAuthInvalidCredentialsException
: if the email address is malformedFirebaseAuthUserCollisionException
: 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:
FirebaseAuthInvalidUserException
: if email doesn't exist or disabled.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());
}
}
}
}
);
这篇关于检查是否存在电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!