eAuthWeakPasswordException永远不会被抓

eAuthWeakPasswordException永远不会被抓

我不知道为什么FirebaseAuthWeakPasswordException永远不会被抓住。只要是WEAK_PASSWORD,就会抛出FirebaseException而不是FirebaseAuthExceptionFirebaseAuthWeakPasswordException。因此,即使使用getErrorCode()方法也无法检查。

    firebaseAuth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // registered
                    } else {
                        try {
                            throw task.getException();
                        } catch(FirebaseAuthWeakPasswordException e) {
                            passwordEditText.setError(getString(R.string.error_weak_password));
                            passwordEditText.requestFocus();
                        } catch(FirebaseException e) {
                            Log.e(TAG, e.getMessage());
                        }
                    }
                }
            });


我怎么知道是否是WEAK_PASSWORD异常?

最佳答案

我正面临着同样的问题。我目前正在使用Firebase 10.2.4。由于某种原因,它将引发Firebase异常,而不是FirebaseAuthWeakPasswordException。我的解决方案是在客户端验证密码的长度,如果长度少于6个字符,我会向用户显示Toast。

private void signUp(){
    email = etEmail.getText().toString().trim();
    password = etPassword.getText().toString().trim();

    if(email.equals("")){
        Toast.makeText(getActivity(),"Please enter your email",Toast.LENGTH_SHORT).show();
        return;
    }

    if(password.equals("")){
        Toast.makeText(getActivity(),"Please enter your password",Toast.LENGTH_SHORT).show();
        return;
    }else if(password.length() < 6){
        Toast.makeText(getActivity(),"Your password is too week please enter a password more than 6 characters",Toast.LENGTH_SHORT).show();
        return;
    }

   signUpFirebeaseListener.createNewUser(email,password);

}

09-16 04:51