@Override
    public boolean checkCredentials(String username, String password) {
        if (username == null || password == null) {
            return false;
        }

        Credentials credentials = new Credentials(username, password);
        if (validCredentialsCache.contains(credentials)) {
            return true;
        } else if (invalidCredentialsCache.contains(credentials)) {
            return false;
        }

        boolean isValid =
                this.username.equals(username)
                        && this.passwordHash.equals(
                                generatePasswordHash(algorithm, salt, password));

        if (isValid) {
            validCredentialsCache.add(credentials);
        } else {
            invalidCredentialsCache.add(credentials);
        }

        return isValid;
    }
@Test
    public void test_upperCase() throws Exception {
        String[] algorithms = new String[] {"SHA-1", "SHA-256", "SHA-512"};

        for (String algorithm : algorithms) {
            String hash = hash(algorithm, VALID_PASSWORD, SALT).toUpperCase();

            MessageDigestAuthenticator messageDigestAuthenticator =
                    new MessageDigestAuthenticator("/", VALID_USERNAME, hash, algorithm, SALT);

            for (String username : TEST_USERNAMES) {
                for (String password : TEST_PASSWORDS) {
                    boolean expectedIsAuthenticated =
                            VALID_USERNAME.equals(username) && VALID_PASSWORD.equals(password);
                    boolean actualIsAuthenticated =
                            messageDigestAuthenticator.checkCredentials(username, password);
                    assertEquals(expectedIsAuthenticated, actualIsAuthenticated);
                }
            }
        }
    }