0
votes

Hi im making a app with a register page where the user enters email, password, shared secret and then a sign in page. Using firestore i store the users shared secret which works fine. I also use the firebase authentication method for email and password. The issue i have is on the sign up page using the firebase authentication signInWithEmailAndPassword method i can only call the email and password. How would i go about checking the shared secret of the user as well as the email and password?

thanks for any help

2

2 Answers

1
votes

When using email and password based sign-in, Firebase Authentication only lets you use that email and password pair to authenticate the user. It has no concept of a shared secret. If you want to check additional data, you will have to do that after the user is signed in, and decide what to do if the data doesn't match.

1
votes

The easiest way that I know how to do this is to add additional statements. I am assuming the shared secret is saved in the Realtime database. In this case, you are going to want to call that data and compare it to the user's input:

FirebaseAuth auth;
DatabaseReference secretRef; //before onCreate
private String currentUserId;

Now for your signin method

final EditText sharedSecret = findViewById(R.id.sharedSecret); //find user input
auth = FirebaseAuth.getInstance();
currentUserId = mAuth.getCurrentUser().getUid();
secretRef = FirebaseDatabase.getInstance().getReference().child("User").child(currentUserId).child("sharedSecret");
final String checkedSecret = secretRef.toString();

Then you would compare it by using code like:

if(checkedSecret != sharedSecret)
{
//user is not login
}else{
//continue with login
}

Good luck