code: def authenticate(self, driver):
          
          #                      0                      1                    2                    3
          events = [driver.username_re, driver.password_re, self.device.prompt_re, driver.rommon_re,
                    #       4             5                   6                       7                8
                    driver.unable_to_connect_re, driver.authentication_error_re, pexpect.TIMEOUT, pexpect.EOF]
  
          transitions = [
              (driver.username_re, [0], 1, partial(a_send_username, self.username), 10),
              (driver.username_re, [1], 1, None, 10),
              (driver.password_re, [0, 1], 2, partial(a_send_password, self._acquire_password()),
               _C['first_prompt_timeout']),
              (driver.username_re, [2], -1, a_authentication_error, 0),
              (driver.password_re, [2], -1, a_authentication_error, 0),
              (driver.authentication_error_re, [1, 2], -1, a_authentication_error, 0),
              (self.device.prompt_re, [0, 1, 2], -1, None, 0),
              (driver.rommon_re, [0], -1, partial(a_send, "\r\n"), 0),
              (pexpect.TIMEOUT, [0], 1, partial(a_send, "\r\n"), 10),
              (pexpect.TIMEOUT, [2], -1, None, 0),
              (pexpect.TIMEOUT, [3, 7], -1, ConnectionTimeoutError("Connection Timeout", self.hostname), 0),
              (driver.unable_to_connect_re, [0, 1, 2], -1, a_unable_to_connect, 0),
          ]
          self.log("EXPECTED_PROMPT={}".format(pattern_to_str(self.device.prompt_re)))
          fsm = FSM("CONSOLE-SERVER-AUTH", self.device, events, transitions, timeout=_C['connect_timeout'],
                    init_pattern=self.last_pattern)
          return fsm.run()
docs: Authenticate using the Console Server protocol specific FSM.