'Authenticate with a registry. Similar to the ``docker login`` command.
Args:
username (str): The registry username
password (str): The plaintext password
email (str): The email for the registry account
registry (str): URL to the registry.  E.g.
``https://index.docker.io/v1/``
reauth (bool): Whether or not to refresh existing authentication on
the Docker server.
dockercfg_path (str): Use a custom path for the Docker config file
(default ``$HOME/.docker/config.json`` if present,
otherwise``$HOME/.dockercfg``)
Returns:
(dict): The response from the login request
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error.'

def login(self, username, password=None, email=None, registry=None, reauth=False, insecure_registry=False, dockercfg_path=None):

    if insecure_registry:
        warnings.warn(INSECURE_REGISTRY_DEPRECATION_WARNING.format('login()'), DeprecationWarning)
    if (dockercfg_path and os.path.exists(dockercfg_path)):
        self._auth_configs = auth.load_config(dockercfg_path)
    elif (not self._auth_configs):
        self._auth_configs = auth.load_config()
    authcfg = auth.resolve_authconfig(self._auth_configs, registry)
    if (authcfg and (authcfg.get('username', None) == username) and (not reauth)):
        return authcfg
    req_data = {'username': username, 'password': password, 'email': email, 'serveraddress': registry}
    response = self._post_json(self._url('/auth'), data=req_data)
    if (response.status_code == 200):
        self._auth_configs[(registry or auth.INDEX_NAME)] = req_data
    return self._result(response, json=True)
