Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:33:22+00:00 2026-05-26T08:33:22+00:00

I am trying to authenticate user using LDAP I am using this code: public

  • 0

I am trying to authenticate user using LDAP

I am using this code:

public bool IsAuthenticated(string domain, string username, string pwd)
{

DirectoryEntry nRoot = new DirectoryEntry("LDAP://192.134.1.142/dc=testDomain,dc=com");
nRoot.AuthenticationType = AuthenticationTypes.None;
nRoot.Username = "uid=username,dc=testDomain,DC=com";  //full dn
nRoot.Password = "pwd";

try
{ 
//Bind to the native AdsObject to force authentication.
Object obj = nRoot.NativeObject;

DirectorySearcher search = new DirectorySearcher(nRoot);

search.SearchScope = SearchScope.Subtree;
search.Filter = "uid=username";               
search.PropertiesToLoad.Add("uid");

SearchResult sr = search.FindOne();
if(null == sr )
{
  return false;
}
// Update the new path to the user in the directory
_path = sr.Path;
_filterAttribute = (String)result.Properties["uid"][0];
  }
 catch (Exception ex)
 {
 throw new Exception("Error authenticating user. " + ex.Message);
 }
 return true;
 }

Here if the user is not a part of any OU the code runs fine but if it is a part of an OU it won’t work and ii get an error

System.Runtime.InteropServices.COMException
at
// Bind to the native AdsObject to force authentication.
Object obj = nRoot.NativeObject;

How do I get the user validated belonging to an OU or any other group??

I tried hard coding the OU to and it worked, but i cannot ask a user to enter his OU

 nRoot.Username = "uid=username,ou=test,dc=testDomain,DC=com";  //full dn
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:33:23+00:00Added an answer on May 26, 2026 at 8:33 am

    You need to take the username, find the object whose uid=username, and then read the distinguishedName attribute or else the name of the returned object (which will be the full DN) and log in with that discovered full DN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to NTLM/LDAP and trying to authenticate using NTML running on
I'm trying to authenticate a user through the RESTful API (not Connect) but I
I'm currently trying to authenticate via Active Directory Services using the PrincipalContext class. I
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I'm trying to build a web service using Ruby on Rails. Users authenticate themselves
I am trying to authenticate to a Google account using Google's ClientLogin method. I
How can I authenticate a user (with username and password) of an ASP.NET MVC
I'm trying to send SMTP e-mails using PHPMailer, but I keep getting this error
I 'm trying to implement user authentication and authorization using roles table, user table
I am trying to get the windows username in my controller after using windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.