`FirebaseAuthWeakPasswordException`永远不会被捕获

时间:2017-02-17 23:59:51

标签: android authentication firebase

我想知道为什么FirebaseAuthWeakPasswordException永远不会被抓住。只要WEAK_PASSWORDFirebaseException,就会抛出FirebaseAuthException而不是FirebaseAuthWeakPasswordExceptiongetErrorCode()。因此,我甚至无法使用 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

我怎么知道它是否是this.shuffledDeck.push(this.deck[Math.floor(Math.random() * this.deck.length)]); 例外?

1 个答案:

答案 0 :(得分:2)

我面临同样的问题。我目前正在使用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);

}