October 25, 2021

Samir Daoudi's Technical Blog

SharePoint, Office 365, C#, .Net, SQL Server News, Tips, Ebooks, Events, Webinars ….etc

C#, Authenticate against AD

In one of the projects I am working on, I had to authenticate the logged in user, and before considering using the Request object and checking the authenticated user, I had a different requirements, and a very particular scenario.

Here is the code snippet in which I pass the username and password which will be authenticated against AD and the result stored in a boolean.

Before running this code, you need to reference to the following namespace:

using System.DirectoryServices.AccountManagement;

You need to have the IP adress for your local AD serverr, which will be used to create an instance of the PrincipalContext object.

PrincipalContext pc = new PrincipalContext(ContextType.Domain, "192.168.16.XXX");
bool isValid = pc.ValidateCredentials(C_UserName.Value, C_Password.Value);

Leave a comment

Copyright © All rights reserved. | Newsphere by AF themes.
Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.