I am trying to create a module that will check for two databases when logging in a user to Drupal. If drupal's native login is a success but the external application does not have that account, then the module will create an account on the external application. If the account is not on drupal but is on the external application then drupal will create a local account. If the user does not exist on either database then the login will fail. Which hook(s) would I need to implement this in a module?