Click here to Skip to main content
15,884,099 members
Articles / Programming Languages / C#

LumiSoft MailServer

Rate me:
Please Sign up or sign in to vote.
3.79/5 (22 votes)
17 Nov 2006CPOL1 min read 321.3K   4.9K   74  
Full featured SMTP/POP3/IMAP server
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;

namespace LumiSoft.MailServer
{
	/// <summary>
	/// Windows logon provider.
	/// </summary>
	public class WinLogon
	{
		[DllImport("advapi32.dll", SetLastError=true)]
		private extern static bool LogonUser(string userName,string domainName,string password,int dwLogonType,int dwLogonProvider,ref IntPtr phToken);

        #region static method Logon

        /// <summary>
		/// Logs user to windows.
		/// </summary>
		/// <param name="domain">Windows domain.</param>
		/// <param name="userName">User name.</param>
		/// <param name="password">Password.</param>
		/// <returns>Returns true if logon successful.</returns>
		public static bool Logon(string domain,string userName,string password)
		{
			IntPtr tokenHandle = new IntPtr(0);

			const int LOGON32_PROVIDER_DEFAULT = 0;
			//This parameter causes LogonUser to create a primary token.
			const int LOGON32_LOGON_INTERACTIVE = 2;

			tokenHandle = IntPtr.Zero;

			if(LogonUser(userName,domain,password,LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,ref tokenHandle)){
				return true;				
			}

			return false;
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions