System.Net.Mail.SmtpLoginAuthenticationModule.Authenticate C# (CSharp) Method

Authenticate() public method

public Authenticate ( string challenge, NetworkCredential credential, object sessionCookie, string spn, ChannelBinding channelBindingToken ) : Authorization
challenge string
credential NetworkCredential
sessionCookie object
spn string
channelBindingToken System.Security.Authentication.ExtendedProtection.ChannelBinding
return Authorization
        public Authorization Authenticate(string challenge, NetworkCredential credential, object sessionCookie, string spn, ChannelBinding channelBindingToken)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
            try
            {
                lock (_sessions)
                {
                    NetworkCredential cachedCredential;
                    if (!_sessions.TryGetValue(sessionCookie, out cachedCredential))
                    {
                        if (credential == null || ReferenceEquals(credential, CredentialCache.DefaultNetworkCredentials))
                        {
                            return null;
                        }

                        _sessions[sessionCookie] = credential;

                        string userName = credential.UserName;
                        string domain = credential.Domain;

                        if (domain != null && domain.Length > 0)
                        {
                            userName = domain + "\\" + userName;
                        }

                        return new Authorization(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(userName)), false);
                    }
                    else
                    {
                        _sessions.Remove(sessionCookie);

                        return new Authorization(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(cachedCredential.Password)), true);
                    }
                }
            }
            finally
            {
                if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
            }
        }