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) {
}
});
2 回答
我这样做了首先,我从数据库中获取特定电子邮件ID的数据,然后比较其密码并分配相关功能 .
谢谢..
我假设您知道如何使用ValueEventListener,onDataChange方法和Datasnapshot .
如上所述,您希望在SQL或MySQL中执行此操作 . 因此,我将使用用户名和密码,而不是使用电子邮件 .
您无需使用Firebase身份验证即可对用户进行身份验证 . 但是,建议不要将其用于数据库安全性 .
如您所见,我已在firebase db中保存了userName和userId . 当用户输入用户名和密码时,您应该使用userAuth中的用户名来读取userId . 检索到userID后,使用它来访问userList以获取用户详细信息 . 您可以在此处检查输入的密码 .
或者您可以像这样验证您的用户 .