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 3437610
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:05:11+00:00 2026-05-18T08:05:11+00:00

I need to verify users in the company using only their username – not

  • 0

I need to verify users in the company using only their username – not their password.

So I need a method like this

public bool UserExists(string username)
{ ... }

I am aware of the System.DirectoryServices namespace but don’t know where to start.

Any ideas?

There are 80,000+ records so try to bear that in mind.

Thank you.

Edit:

I have done it – my code is:

private bool UserExists(string userName, string domain)
{
    try
    {
        DirectoryEntry.Exists("WinNT://" + domain + ".[hidden].com/" + userName);
        return true;
    }
    catch (COMException)
    {
        return false;
    }
}

I don’t know if it is correct, but it seems to work so far.

Michael’s answer has two relevant parts:

  • http://www.codeproject.com/KB/system/everythingInAD.aspx#22
  • http://www.codeproject.com/KB/system/everythingInAD.aspx#35

Update #2:

I actually used this:

public static bool LoggedOnUserExists()
{
    var domain = new PrincipalContext(ContextType.Domain);

    UserPrincipal foundUser = UserPrincipal.FindByIdentity(domain, IdentityType.SamAccountName, Environment.UserName);

    return foundUser != null;
}
  • 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-18T08:05:11+00:00Added an answer on May 18, 2026 at 8:05 am

    In .NET 3.5 and up, you can use the System.DirectoryServices.AccountManagement namespaces to do this quite simply:

    public bool UserExists(string username)
    {
       // create your domain context
       using (PrincipalContext domain = new PrincipalContext(ContextType.Domain))
       {
           // find the user
           UserPrincipal foundUser = UserPrincipal.FindByIdentity(domain, IdentityType.Name, username);
    
           return foundUser != null;
        }
    }
    

    This will work with the regular user name John Doe, or alternatively you can use the user’s e-mail address (john.doe@company.com), or his distinguished name (CN=John Doe) – see what the IdentityType enumeration has to offer 🙂

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

Sidebar

Related Questions

I'm using browser automation for testing web sites but I need to verify HTTP
I'm using browser automation for testing web sites but I need to verify HTTP
I've been running a small web-based experiemnt using Facebook UIDs to verify unique users.
How do I prevent users from calling a method doAction in my controller using
I am having an ASP.net Membership I need to verify the User Question and
I need some easy API to verify that a PE file is valid &
Need to an expression that returns only things with an I followed by either
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
I need to verify the correct function of an application I am working with,
I am developing an ASP.Net application that will need to verify that the user

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.