使用电子邮件以及用户名和密码进行Firebase身份验证 [英] firebase authentication with email and username and password

查看:89
本文介绍了使用电子邮件以及用户名和密码进行Firebase身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用电子邮件和用户名+密码登录,我有一个项目,希望用户添加一个唯一的号码(实际上这是我们公司提供的我们的工作识别号码)能够登录该程序将对公司雇用不公开.

I am wondering if there is the ability to sign in with email and user id + password , I have a project that I want user to add a unique number ( actually it is our work identify number provided by our company ) to be able to sign in to the program will stay private to company employment .

即使电子邮件和密码正确但用户ID错误,我也需要Firebase身份验证来拒绝登录.

I need the firebase authentication to refuse login even if email and password are correct but the user id is wrong.

推荐答案

您可以使用数据库检查ID是否相同.

You can use the database to check if the id is the same or not.

您可以创建以下数据库:

You can create the following database:

users
   userId
      userCompanyId : id
      email         : email@gmail.com

因此,您可以首先根据用户的电子邮件和密码对用户进行身份验证,然后检查用户输入的ID或唯一编号是否与数据库中的ID相同:

So you can first authenticate the user based on his email and password and then, check if the id or unique number entered by the user is the same as the one in the database:

mAuth.createUserWithEmailAndPassword(email, password)
        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                      // retrieve Id from database and check if it is the same
                } else {
                    //sign in failed
                    Log.w(TAG, "createUserWithEmail:failure", task.getException());
                }
            }
        });

这篇关于使用电子邮件以及用户名和密码进行Firebase身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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