[英]How can I get password from Firebase database and match with edittext?
I am new in android studio and java as well我是 android 工作室和 java 的新手
I created on firebasedatabase codes and I want to code it as shown below我在 firebasedatabase 代码上创建,我想按如下所示对其进行编码
Class aclass {
String codeX= someedittext.toString();
String codeY= coderetrievedfromfirebase.toString();
if (codex=codey){do something};
}
Thanks in advance提前致谢
You may use FirebaseAuth to authenticate your email and password by using below code:-您可以使用FirebaseAuth使用以下代码验证您的 email 和密码:-
private FirebaseAuth mAuth = FirebaseAuth.getInstance();
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithEmail:failure", task.getException());
Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
updateUI(null);
}
// ...
}
});
updateUI:更新界面:
private void updateUI(FirebaseUser user){
if (user != null) {
// Name, email address, and profile photo Url
String name = user.getDisplayName();
String email = user.getEmail();
Uri photoUrl = user.getPhotoUrl();
// Check if user's email is verified
boolean emailVerified = user.isEmailVerified();
// The user's ID, unique to the Firebase project. Do NOT use this value to
// authenticate with your backend server, if you have one. Use
// FirebaseUser.getIdToken() instead.
String uid = user.getUid();
}
}
For more information you may go through Google Firebase Authentication有关更多信息,您可以通过Google Firebase 身份验证 go
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.