使用存储在Firebase实时数据库中的电子邮件登录 [英] Login using email stored in firebase realtime database

查看:68
本文介绍了使用存储在Firebase实时数据库中的电子邮件登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,其中实现了Firebase实时数据库.现在,我想使用存储在数据库中的电子邮件ID和密码登录.我知道可以使用firebase auth进行身份验证,但是我想像在Sql或sql中一样使用实时数据库登录.

I am developing an android App in which I implemented Firebase realtime database. And now I want to login using by email id and password which stored in database. I know firebase auth can be use for authentication but I want to login using realtime database like we do in Sql or my sql.

推荐答案

我做到了.首先,我从数据库中获取特定电子邮件ID的数据,然后比较其密码并分配相关的功能.

I done this. First I fetch data of particular email id from database and than compare its password and assign the related function to do..

Query query = databaseReference.child("users").orderByChild("email").equalTo(txvUsername.getText().toString().trim());
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                // dataSnapshot is the "issue" node with all children with id 0

                for (DataSnapshot user : dataSnapshot.getChildren()) {
                    // do something with the individual "issues"
                    UsersBean usersBean = user.getValue(UsersBean.class);

                    if (usersBean.password.equals(txvPassword.getText().toString().trim())) {
                        Intent intent = new Intent(context, MainActivity.class);
                        startActivity(intent);
                    } else {
                        Toast.makeText(context, "Password is wrong", Toast.LENGTH_LONG).show();
                    }
                }
            } else {
                Toast.makeText(context, "User not found", Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

谢谢..

这篇关于使用存储在Firebase实时数据库中的电子邮件登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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