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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:44:10+00:00 2026-05-22T22:44:10+00:00

I have WPF application that has a login form. I would like to make

  • 0

I have WPF application that has a login form. I would like to make all existing windows users that belong to some specific group able to log into my application.

So what I need is a way after the user have given his username and password to see if this is a user, belonging to the wanted group, and that the password is correct. The feedback I can use to decide if the user gets logged in or not.

  • 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-22T22:44:11+00:00Added an answer on May 22, 2026 at 10:44 pm

    If you need to find out if the user has membership to some AD group, you will need to use the group’s SID if the user is not a “direct” member of the group (i.e. the user is a member of a nested group which itself is a member of the ‘desired’ AD group).

    (I’ve used this for years, but long ago lost the link to where I found it. I believe there’s actually a simpler way to check for nested groups in DirectoryServices 4.0, but I have not used it).

    If you’re using .NET 3.5 (as indicated in the link from Travis), you can check the user’s credentials like this:

    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain)
    {
        if (pc.ValidateCredentials(username, password))
        {
            /* Check group membership */
        }
    }
    

    If you are not using .NET 3.5, you can still check the credentials like this:

    var user = new DirectoryEntry("", username, password)
    try 
    {
        user.RefreshCache();
    
        /* Check group membership */
    }
    catch (DirectoryServicesCOMException ex)
    {
        /* Invalid username/password */
    }
    finally
    {
        user.Close();
    }    
    

    Then, to check, the AD group membership, use the following:

    var user = new DirectoryEntry("", username, password);
    var searcher = new DirectorySearcher();
    searcher.Filter = "(&(objectCategory=group)(samAccountName=" + YourGroupName + "))";
    var group = searcher.FindOne();
    if (group != null && IsMember(group.GetDirectoryEntry(), user))
        /* User is a direct OR nested member of the AD group */
    

    The IsMember helper method:

    static bool IsMember(DirectoryEntry group, DirectoryEntry user)
    {
        group.RefreshCache(new string[] { "objectSid" });
        SecurityIdentifier groupSID =
            new SecurityIdentifier((byte[])group.Properties["objectSid"].Value, 0);
    
        IdentityReferenceCollection refCol;
    
        user.RefreshCache(new string[] { "tokenGroups" });
    
        IdentityReferenceCollection irc = new IdentityReferenceCollection();
    
        foreach (byte[] sidBytes in user.Properties["tokenGroups"])
        {
            irc.Add(new SecurityIdentifier(sidBytes, 0));
        }
        refCol = irc.Translate(typeof(NTAccount));
        PropertyValueCollection props = user.Properties["tokenGroups"];
        foreach (byte[] sidBytes in props)
        {
            SecurityIdentifier currentUserSID = new SecurityIdentifier(sidBytes, 0);
            if (currentUserSID.Equals(groupSID))
            {
                return true;
            }
        }
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application with form that has a textbox named txtStatusWindow. I
I have a WPF application with a form that, when started, invokes a custom
I have an existing application that has some parts of formatted text-blocks (standard formats
I have a WPF application that has a variable x which is an instance
I have a WPF application that has a list box of images. Right now
I have a WPF application that has several modal window used for various purposes.
I have written a WPF Line of Business application that has a particular sections
I have a WPF (C# and .NET 4) application that has a long running
I have a WPF application that has just one button. When the button is
I have a WPF application that runs fine under XP as an administrator. When

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.