有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java验证Firebase 安卓登录系统

我正在安卓 studio java应用程序中验证我的登录系统。 问题是密码验证根本不起作用。我要那个东西阻止不正确的密码,正确时通过。在任务内部更改布尔值并将其值传递给公共布尔值应该可以解决问题,但事实并非如此。 已创建的活动OnViewView:

 public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    //Firebase synch
            inputEmail = (EditText) view.findViewById(R.id.editTextTextEmailAddress);
            inputPassword = (EditText) view.findViewById(R.id.editTextNumberPassword);


    view.findViewById(R.id.button_second).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            NavHostFragment.findNavController(SecondFragment.this)
                    .navigate(R.id.action_SecondFragment_to_FirstFragment);
        }
    });
    view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            //Authentication system
            //If not logged and there is not mail in database, create with that parameters.
            m_email = inputEmail.getText().toString().trim();
            m_pass = inputPassword.getText().toString().trim();

            Auth activity = new Auth();

            if(!m_email.isEmpty() && !m_pass.isEmpty()) {
                //pass if email+password is correct!
                activity.SignIn(m_email, m_pass);
                Boolean b =activity.valid;
                user =mAuth.getCurrentUser();
                //deny access to new view
                if(!user.isAnonymous()){
                    Intent intent = new Intent(getContext(), Managment.class);// New activity
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);

                }
            Snackbar.make(view, "Incorrect auth parameters", Snackbar.LENGTH_LONG)
                    .setAction(R.string.actionmess, null).show();
            }
            //empty fields
            else{
                Snackbar.make(view, "Put all parameters?!", Snackbar.LENGTH_LONG)
                        .setAction(R.string.actionmess, null).show();
            }
            }




    });
};

身份验证类。我将其拆分,这样代码看起来更适合我阅读

    //Sign in#Log in
public void SignIn(String m_email, String m_pass) {

        Task<AuthResult> authRegister = mAuth.signInWithEmailAndPassword(m_email, m_pass);
        new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if(task.isSuccessful())
                    valid = TRUE;
                if(!task.isSuccessful()) {
                    try {
                        throw task.getException();
                    } catch (FirebaseAuthInvalidUserException e) {
                        Log.d("Error", "Invalid account");
                    } catch (FirebaseAuthInvalidCredentialsException e)  {
                        Log.d("Error", "Invalid password");

                    } catch (FirebaseNetworkException e) {

                    } catch (Exception e) {
                        Log.e("error", e.getMessage());
                    }
                    Log.w("error", "signInWithEmail:failed",task.getException());
                }
                valid = FALSE;



            }
        };
}

共 (0) 个答案