我为学生使用的应用创建了一个基本数据库。我希望学生能够使用预定义的用户ID(4位数字)和密码(3个字母)登录....我已经在Firebase中创建了这个。
我尝试了很多组合,但我无法弄清楚如何执行以下操作:
任何有关如何做到这一点的帮助将不胜感激。我附上了我的数据库样本的屏幕截图。谢谢。
编辑:更新....想出来了!可以检查输入的用户ID的相应pw:
b1 = (Button) findViewById(R.id.loginBtn);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (rd1.isChecked()) { //logging on as staff successfully takes you to staff main screen
Intent i = new Intent(getApplicationContext(), MainStaff.class);
startActivity(i);
}
if (rd2.isChecked()) {//logging on as student successfully takes you to quiz screen
//set up mref to get get the password for username entered
DatabaseReference mref = mDatabase.child("student_users").child(e_uname.getText().toString())
.child("password");
mref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//if password entered matches the username entered, allow access to quiz
if (dataSnapshot.getValue().equals(e_pwd.getText().toString())) {
Toast.makeText(getApplicationContext(), "Successfully logged on", Toast.LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(), MainQuiz.class);
startActivity(i);
} else {
Toast.makeText(getApplicationContext(), "Please check UserID and password.", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
});