I'm working on sign up of my project and for authentication I'm using Firebase. Now I want that my code only verify or authenticate only those email addresses which are already created by gmail or yahoo or hotmail. new email address can be authenticate. If user write email which is not created in gmail or yahoo or hotmail. It should not able to register. But my code is taking every random email address whether it is already exists or not. and in firebase authentication table it is showing that email address too. Now what mistake i'm making in my code which is authenticating every email address.
Code:
package com.example.animation;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.AnimationDrawable;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class Signup extends AppCompatActivity {
RelativeLayout myLayout;
AnimationDrawable animationDrawable;
private EditText email_signup, password_signup, name_signup;
private Button signup_btn;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
timing();
setValues();
TextView txt=findViewById(R.id.txt_signup);
txt.setPaintFlags(txt.getPaintFlags()| Paint.UNDERLINE_TEXT_FLAG);
firebaseAuth= FirebaseAuth.getInstance();
signup_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(validate()){
// database
String user_email=email_signup.getText().toString().trim();
String user_password=password_signup.getText().toString().trim();
String user_name=name_signup.getText().toString().trim();
firebaseAuth.createUserWithEmailAndPassword(user_email,user_password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
Toast.makeText(Signup.this,"Registeration Successful",Toast.LENGTH_SHORT).show();
startActivity(new Intent(Signup.this,MainActivity.class));
}
else
{
Toast.makeText(Signup.this,"Not Successful",Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
}
private void timing(){
myLayout=findViewById(R.id.signup_layout);
animationDrawable=(AnimationDrawable)myLayout.getBackground();
animationDrawable.setEnterFadeDuration(2500);
animationDrawable.setExitFadeDuration(2500);
animationDrawable.start();
}
private void setValues(){
email_signup=findViewById(R.id.email_reg);
password_signup=findViewById(R.id.pass_reg);
name_signup=findViewById(R.id.namebox);
signup_btn=findViewById(R.id.btn_register);
}
private Boolean validate(){
Boolean result=false;
String name=name_signup.getText().toString();
String password=password_signup.getText().toString();
String email=email_signup.getText().toString();
if(name.isEmpty()&& password.isEmpty()&&email.isEmpty()){
Toast.makeText(this,"Please enter all Details",Toast.LENGTH_SHORT).show();
}
else{
result=true;
}
return result;
}
}
This is firebase authenticate table: