Active Directory (AD) is an implementation of LDAP directory services by Microsoft for use primarily in Windows environments. Its main purpose is to provide central authentication and authorization services for Windows based computers. Active Directory also allows administrators to assign policies, deploy software, and apply critical updates to an organization. Active Directory stores information and settings in a central database. Active Directory networks can vary from a small installation with a few hundred objects, to a large installation with millions of objects.Microsoft Active Directory provides a directory service that allows organizations to administer their networked resources. The networked resources include users, computers etc. Thus it acts as a central store for users in a particular network. This store can be used for authentication purpose. Applications can request the active directory service for user authentication.
A sample code to authenticate a user against the active directory.
//=================================================================
/// <summary>
/// int: Interactive Logon.
/// </summary>
public const int LOGON32_LOGON_INTERACTIVE = 2;
/// <summary>
/// int: Default Provider.
/// </summary>
public const int LOGON32_PROVIDER_DEFAULT = 0;
/// <summary>
/// int: Network Logon.
/// </summary>
public const int LOGON32_LOGON_NETWORK = 3;
/// <summary>
/// LogonUser is a Windows API, which is used to logon a win user.
/// </summary>
/// <param name="lpszUserName">string: User Name.</param>
/// <param name="lpszDomain">string: Domain name.</param>
/// <param name="lpszPassword">string: Password.</param>
/// <param name="dwLogonType">int: Logon Type.</param>
/// <param name="dwLogonProvider">int: Logon provider.</param>
/// <param name="phToken">ref IntPtr: Logon Token.</param>
/// <returns>int: Status of the user logon.</returns>
/// <remarks>Use to Logon the user to Windows network.</remarks> [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int LogonUser(String lpszUserName, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
/// <summary>
/// This method authenticates the user agains the current domain
/// and returns a boolean value.
/// </summary>
/// <returns>bool: Indicating whether the authentication
/// is successfull.</returns>
public bool AuthenticateUser()
{
string _domainName;
IntPtr _token = IntPtr.Zero;
_domainName = Environment.GetEnvironmentVariable("USERDOMAIN");
//LogonUser to check Windows Logon.
int _intResult LogonUser("USER_NAME", _domainName, "PASSWORD",
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, ref _token);
return Convert.ToBoolean(_intResult); ;
}
//=================================================================
Friday, January 11, 2008
What is active directory?
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment