def METHOD_NAME(self, request, username=None, password=None):
    """Check the username/password and return a User."""
    if not param_tools.get_global_parameter("enabled_imapmigration"):
        return None
    condition = not param_tools.get_global_parameter(
            "auto_create_domain_and_mailbox", "admin")
    if condition:
        # Automatic domain/mailbox is disabled. Deny auth to
        # prevent further issues...
        return None
    self.address, domain = email_utils.split_mailbox(username)
    provider_domain = models.EmailProviderDomain.objects.filter(
        name=domain).select_related("provider").first()
    if not provider_domain:
        # Domain not allowed for migration: failure
        return None
    address = provider_domain.provider.address
    port = provider_domain.provider.port
    try:
        if provider_domain.provider.secured:
            conn = imaplib.IMAP4_SSL(address, port)
        else:
            conn = imaplib.IMAP4(address, port)
    except (socket.error, imaplib.IMAP4.error, ssl.SSLError) as error:
        raise ModoboaException(
            _("Connection to IMAP server failed: %s") % error)
    try:
        typ, data = conn.login(
            smart_bytes(username), smart_str(password))
    except imaplib.IMAP4.error:
        typ = "NO"
    conn.logout()
    if typ != "OK":
        return None
    self.provider_domain = provider_domain
    return self.get_or_create_user(username, password)