protected void validatePassword(UserIdentity userIdentity, String password) throws AuthenticationException {
        if (!Config.enable_validate_password) {
            return;
        }

        //  1. The length of the password should be no less than 8.
        if (password.length() < 8) {
            throw new AuthenticationException("password is too short!");
        }

        // 2. The password should contain at least one digit, one lowercase letter, one uppercase letter
        boolean hasDigit = false;
        boolean hasUpper = false;
        boolean hasLower = false;
        for (int i = 0; i != password.length(); ++i) {
            char c = password.charAt(i);
            if (c >= '0' && c <= '9') {
                hasDigit = true;
            } else if (c >= 'A' && c <= 'Z') {
                hasUpper = true;
            } else if (c >= 'a' && c <= 'z') {
                hasLower = true;
            }
        }
        if (!hasDigit || !hasLower || !hasUpper) {
            throw new AuthenticationException(
                    "password should contains at least one digit, one lowercase letter and one uppercase letter!");
        }

        if (!Config.enable_password_reuse) {
            GlobalStateMgr.getCurrentState().getAuthenticationMgr().checkPlainPassword(
                    userIdentity.getUser(), userIdentity.getHost(), password);
        }
    }
@Test
    public void testValidPassword() throws Exception {
        Config.enable_validate_password = true;

        // too short
        try {
            provider.validatePassword(new UserIdentity("u", "%"), "aaa");
            Assert.fail();
        } catch (AuthenticationException e) {
            Assert.assertTrue(e.getMessage().contains("password is too short"));
        }

        // only number
        String[] badPasswords = {"starrocks", "STARROCKS", "123456789", "STARROCKS123", "starrocks123", "STARROCKSstar"};
        for (String badPassword : badPasswords) {
            try {
                provider.validatePassword(new UserIdentity("u", "%"), badPassword);
                Assert.fail();
            } catch (AuthenticationException e) {
                Assert.assertTrue(e.getMessage().contains(
                        "password should contains at least one digit, one lowercase letter and one uppercase letter!"));
            }
        }

        provider.validatePassword(new UserIdentity("u", "%"), "aaaAAA123");
        Config.enable_validate_password = false;
        provider.validatePassword(new UserIdentity("u", "%"), "aaa");
    }