DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("credentials");
//to store values in your credentials node just use this code
ref.child("usernames").child(username);
ref.child("usernames").child(username).child("password").setValue(password);
// here username and password are the strings you want to store
ref.child("credentials").orderByChild("usernames").equalTo(username).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
// here you can do what you want, like comparing the password of the username and other things you require to do
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
2 回答
如果你想做一些像
usernames
和passwords
之类的特殊登录访问,你可以使用Firebase realtime database
这样做 .您可以创建名为
credentials
的节点,然后将每个新的username
和password
存储在其中 . 然后,要检查某人是否使用正确的详细信息登录,您可以搜索database
记录并将其与用户输入的内容进行匹配 .我所说的,可以编码如下:
您可以与所有新用户一起在应用中注册它们 . 这也使您更容易(阅读更快)搜索特定的
username
和相应的password
.您可以使用以下代码执行此操作:
Firebase auth仅允许您使用电子邮件和密码进行身份验证 . 如果您想使用用户名而不是电子邮件,则可以将用户详细信息存储在数据库中并根据该信息进行身份验证 .
您可以在数据库中遵循此格式来配置身份验证过程 .
在用户名字段中,您可以存储用户的用户名,无论他们选择哪个,都要检查密码 . 通过这种方式,您还可以检查是否已创建用户名 .