[英]Firebase on Android Studio (LoginScreen)
So I'm trying to create a login screen for my app in java on Android Studio using Firebase.所以我正在尝试使用 Firebase 在 Android Studio 上的 Java 中为我的应用程序创建一个登录屏幕。 Currently, in creating accounts, I am doing it this way:
目前,在创建帐户时,我是这样做的:
if (password.getText().toString().equals(confirm.getText().toString())) {
Map map = new HashMap<String, String>();
map.put(username.getText().toString(), password.getText().toString());
myFirebaseRef.push().setValue(map);
error.setText("Account created!");
}
else {
error.setText("Passwords do not match");
}
But it saves the data on my Firebase like this但它像这样将数据保存在我的 Firebase 上
So now on my login screen, once a user types in their username, I wanna search my Firebase for the username, and make sure it exists, then see if the password matches what they entered.所以现在在我的登录屏幕上,一旦用户输入他们的用户名,我想在我的 Firebase 中搜索用户名,并确保它存在,然后查看密码是否与他们输入的内容匹配。 How Would I do that?
我该怎么做? Thanks!
谢谢!
As Amy already said: no matter what else you do, immediately change your code to stop storing passwords in plain text .正如 Amy 已经说过的:无论您做什么,立即更改您的代码以停止以纯文本形式存储密码。 That is an incredibly bad practice.
这是一种非常糟糕的做法。 In general authentication is better left to dedicated tools, such as Firebase Authentication .
一般来说,身份验证最好留给专用工具,例如Firebase 身份验证。
Aside from that, you'll want to change the way you store the users a bit.除此之外,您还需要稍微改变存储用户的方式。 It seems you identify users by their name, store them under their name:
似乎您通过姓名识别用户,将他们存储在他们的姓名下:
Map map = new HashMap<String, String>();
map.put(username.getText().toString(), password.getText().toString());
myFirebaseRef.updateChildren(map);
Now you can look up a user by their name with:现在,您可以使用以下命令按用户名查找用户:
Firebase userRef = myFirebaseRef.child(username.getText().toString());
userRef.addListenerForSingleValueEvent(...
See the Firebase guide on reading data for more on that.有关更多信息,请参阅有关读取数据的Firebase 指南。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.