I want to check when a user attempts to signup with createUserWithEmailAndPassword()
in Firebase user Authentication method, this user is already registered with my app.
You can use Firebase Authentication to let your users authenticate with Firebase using their email addresses and passwords, and to manage your app's password-based accounts.
If you are u storing the user and password in firebase authentication then no it is not possible to view the password written by the user. You can store the password in the database but if someone got access to your database they can know all the passwords of the users using your application.
If you haven't yet connected your app to your Firebase project, do so from the Firebase console. Enable Email/Password sign-in: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Email/password sign-in method and click Save.
To detect whether a user with that email address already exists, you can detect when the call to createUserWithEmailAndPassword ()
fails with auth/email-already-in-use
. I see that @Srinivasan just posted an answer for this.
Alternatively, you can detect that an email address is already used by calling fetchSignInMethodsForEmail()
.
The usual flow for this is that you first ask the user to enter their email address, then call fetchSignInMethodsForEmail
, and then move them to a screen that either asks for the rest of their registration details (if they're new), or show them the provider(s) with which they're signed up already.
When the user trying to create an user with same email address, the task response will be "Response: The email address is already in use by another account."
mFirebaseAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
//User registered successfully
}else{
Log.i("Response","Failed to create user:"+task.getException().getMessage());
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With