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

  • Home
  • SEARCH
  • 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 7128775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:10:25+00:00 2026-05-28T11:10:25+00:00

In C#, how do I authenticate a user on a network machine? For example,

  • 0

In C#, how do I authenticate a user on a network machine? For example, I want to authenticate the user testuser with password testpassword on the machine EXAMPLEMACHINE from a different machine which is network-connected to EXAMPLEMACHINE. For example, I am on MYMACHINE and I want to authenticate testuser with testpassword on EXAMPLEMACHINE.

I have tried the following but it keeps telling me that, The LDAP server is unavailable:

PrincipalContext context =
    new PrincipalContext(ContextType.Domain, exampleMachineDomain);
return context.ValidateCredentials(username, password);
  • 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-28T11:10:25+00:00Added an answer on May 28, 2026 at 11:10 am

    If you are not using Active Directory, you could use something like this:

    using System.Security;
    using System.DirectoryServices.AccountManagement;
        public struct Credentials
        {
            public string Username;
            public string Password;
        }
        public class Domain_Authentication
        {
            public Credentials Credentials;
            public string Domain;
            public Domain_Authentication(string Username, string Password, string SDomain)
            {
                Credentials.Username = Username;
                Credentials.Password = Password;
                Domain = SDomain;
            }
            public bool IsValid()
            {
                using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Domain))
                {
                    // validate the credentials
                    return pc.ValidateCredentials(Credentials.Username, Credentials.Password);
                }
            }
        }
    

    If you are using Active Directory, you could use something like this:

     PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    
        // define a "query-by-example" principal - here, we search for a UserPrincipal 
        UserPrincipal qbeUser = new UserPrincipal(ctx);
    
        // if you're looking for a particular user - you can limit the search by specifying
        // e.g. a SAMAccountName, a first name - whatever criteria you are looking for
        qbeUser.SamAccountName = "johndoe";
    
        // create your principal searcher passing in the QBE principal    
        PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
    
        // find all matches
        foreach(var found in srch.FindAll())
        {
            // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....          
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application in which I want to authenticate a user from a
How can I authenticate user from multiple source altogether ? For example local (ZODB
I want to be able to authenticate a user by using their domain UserId
What's the best way to authenticate and track user authentication state from page to
I want to be able to authenticate an NT username/password combination through an ASP.NET
I'm attempting to authenticate a user against ADAM using a user I created in
I'm trying to authenticate a user through the RESTful API (not Connect) but I
I have a login page where I authenticate the user. When the authentication pass,
I have a asp.net application which is working from last 2-3 years, it has
I have windows server 2003 machine as a part of our network. I have

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.