Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The email address is badly formatted Firebase

hi i am working on a android project where i am using firebase as back-end and i am building a signup and login form . When ever i sign up the code is working well and . When i try to retrieve it using "signInWithEmailAndPassword i am getting the fallowing error. The email address is badly formatted Firebase`

login Activity

public class LoginActivity extends AppCompatActivity {

    private EditText mLoginEmailField;
    private EditText mloginPassField;

    private Button mLoginbtn;
    private Button mNewAccountbtn;

    private DatabaseReference mDatabaseRefrence;





    private FirebaseAuth mAuth;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);



        mAuth = FirebaseAuth.getInstance();
        mLoginEmailField = (EditText) findViewById(R.id.loginEmailField);
        mloginPassField = (EditText) findViewById(R.id.loginPasswordField);

        mLoginbtn = (Button) findViewById(R.id.loginBtn);
        mNewAccountbtn = (Button) findViewById(R.id.newAccountbtn);
        mDatabaseRefrence = FirebaseDatabase.getInstance().getReference().child("Users");


        mNewAccountbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent rigisterIntent = new Intent(LoginActivity.this,RigisterActivity.class);
                rigisterIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(rigisterIntent);
            }
        });


        mLoginbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                CheckLogin();
            }
        });
    }

    private void CheckLogin() {

        String email = mloginPassField.getText().toString().trim();
        String pass = mloginPassField.getText().toString().trim();


        if(!TextUtils.isEmpty(email) && !TextUtils.isEmpty(pass)){


            mAuth.signInWithEmailAndPassword(email,pass).addOnCompleteListener(this,new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if(task.isSuccessful()){
                        CheackUserExsists();
                    }else{
                        System.out.println("Sign-in Failed: " + task.getException().getMessage());
                        Toast.makeText(LoginActivity.this,"Erorr Login",Toast.LENGTH_LONG).show();
                    }
                }
            });

        }

    }

    private void CheackUserExsists() {

     final String user_id = mAuth.getCurrentUser().getUid();
        mDatabaseRefrence.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if(dataSnapshot.hasChild(user_id)){

                    Intent MainIntent = new Intent(LoginActivity.this,MainActivity.class);
                    MainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(MainIntent);
                }else
                {

                    Toast.makeText(LoginActivity.this,"You need to setup your Account.. ",Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }
}

Rigister Actvity

public class RigisterActivity extends AppCompatActivity {

    private EditText mNameField;
    private EditText mPassField;
    private EditText mEmailField;

    private Button mRigisterbtn;

    private ProgressDialog mProgres;

    private DatabaseReference mDatabase;


    private FirebaseAuth mAuth;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rigister);

        mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");

        mAuth = FirebaseAuth.getInstance();

        mProgres = new ProgressDialog(this);

        mNameField = (EditText) findViewById(R.id.nameField);
        mPassField = (EditText) findViewById(R.id.passFiled);
        mEmailField = (EditText) findViewById(R.id.emailField);

        mRigisterbtn = (Button) findViewById(R.id.rigisterbtn);

        mRigisterbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StartRigister();
            }
        });

    }

    private void StartRigister() {

        final String name = mNameField.getText().toString().trim();
        String pass = mPassField.getText().toString().trim();
        String email = mEmailField.getText().toString().trim();

        if(!TextUtils.isEmpty(name) && !TextUtils.isEmpty(pass) && !TextUtils.isEmpty(email)){

            mProgres.setMessage("Signing Up... ");
            mProgres.show();

               mAuth.createUserWithEmailAndPassword(email,pass).addOnCompleteListener(this,new OnCompleteListener<AuthResult>() {
                   @Override
                   public void onComplete(@NonNull Task<AuthResult> task) {

                       if(task.isSuccessful()){
                         String user_id = mAuth.getCurrentUser().getUid();
                           DatabaseReference CurentUser_db =  mDatabase.child(user_id);
                           CurentUser_db.child("name").setValue(name);
                           CurentUser_db.child("image").setValue("defalut");
                        mProgres.dismiss();
                           Intent mainIntent = new Intent(RigisterActivity.this, MainActivity.class);
                           mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                           startActivity(mainIntent);
                       }

                   }
               });

        }


    }
}

I have made sure that i have setup email and password active in the auth section of firebase.

still firebase giving me the following error.

like image 592
Divakar R Avatar asked Sep 23 '16 15:09

Divakar R


2 Answers

Your code to set email is incorrect. You are setting email to the value of the EditText for password.

In method CheckLogin(), change:

String email = mloginPassField.getText().toString().trim();

to:

String email = mLoginEmailField .getText().toString().trim();
like image 141
Bob Snyder Avatar answered Oct 10 '22 05:10

Bob Snyder


Simply use Edittext named as Email and Password you need not do anything. the error comes up only if you use plaintext for both...

like image 34
Aniket Malik Avatar answered Oct 10 '22 06:10

Aniket Malik