class MySQLAuthenticationHandler {

    public Optional<MySQLServerErrorCode> login(final String username, final byte[] authResponse, final String database) {
        Optional<ProxyUser> user = getUser(username);
        if (!user.isPresent() || !isPasswordRight(user.get().getPassword(), authResponse)) {
            return Optional.of(MySQLServerErrorCode.ER_ACCESS_DENIED_ERROR);
        }
        if (!isAuthorizedSchema(user.get().getAuthorizedSchemas(), database)) {
            return Optional.of(MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR);
        }
        return Optional.empty();
    }

}