def authenticate(self, username=None, password=None):
u = self.username<EOL>p = self.password<EOL>if username and password:<EOL><INDENT>u = username<EOL>p = password<EOL><DEDENT>client = self.client()<EOL>query = client.authenticated_query(username=u, password=p)<EOL>res = client.post(query)<EOL>ofx = BeautifulSoup(res, '<STR_LIT>')<EOL>sonrs = ofx.find('<STR_LIT>')<EOL>code = int(sonrs.find('<STR_LIT:code>').contents[<NUM_LIT:0>].strip())<EOL>try:<EOL><INDENT>status = sonrs.find('<STR_LIT:message>').contents[<NUM_LIT:0>].strip()<EOL><DEDENT>except Exception:<EOL><INDENT>status = '<STR_LIT>'<EOL><DEDENT>if code == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>raise ValueError(status)<EOL>
Test the authentication credentials

        Raises a ``ValueError`` if there is a problem authenticating
        with the human readable reason given by the institution.

        :param username: optional username (use self.username by default)
        :type username: string or None
        :param password: optional password (use self.password by default)
        :type password: string or None