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.
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:
If you are not using .NET 3.5, you can still check the credentials like this:
Then, to check, the AD group membership, use the following:
The IsMember helper method: