检查是否存在电子邮件 [英] Check if given email exists

查看:407
本文介绍了检查是否存在电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法知道用户输入的电子邮件在Firebase中是否真实?内置的注册电子邮件和密码方法有这个功能吗?



编辑:抱歉的误解。我不在乎以前是否使用过电子邮件,我需要知道的是:如果输入的电子邮件是制造或真实的,存在的


创建时请阅读 createUserWithEmailAndPassword Docs



createUserWithEmailAndPassword throws 3例外:
$ b

  • FirebaseAuthWeakPasswordException :如果密码不够好

  • FirebaseAuthInvalidCredentialsException :如果电子邮件地址格式不正确

  • code> FirebaseAuthUserCollisionException :如果已经存在具有给定电子邮件地址的帐户。
    您可以在 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 抛出两个例外:


    1. 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:

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

    这篇关于检查是否存在电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆