1

I have a login form written in C# and I want only AD users to be able to login.
How should I do this?

string UserName = "";
string Pass = "";
Iain Ward
  • 9,850
  • 5
  • 34
  • 41
Nissim
  • 31
  • 1
  • 5

3 Answers3

0

I am sure that this is not a best practice, but, depending on your security needs, you could allow all domain users and exclude local users by checking just the UserDomainName in the Form_Load. This simple approach piggybacks on their computer login, and does not have the complexity of any LDAP/AD calls.

if (SystemInformation.UserDomainName.ToString() == "myDomain")
{
    // your normal form load code here
}
else
{
   form1.Close(); //this is a simple but effective to pull the rug out from 
                  //under them if they do not have the permissions
   //TODO email the application administrator the `SystemInformation.UserName` of the user who was not given permissions
}

In my environment, since our in-house apps are deployed via ClickOnce (installed per user per computer), a similar approach (we compare usernames too) has always been sufficient for us.

wruckie
  • 1,717
  • 1
  • 23
  • 34
  • This is not what I meant. I want to authorize domain user name and PASSWORD!! from the AD – Nissim Apr 16 '14 at 21:30
  • You did not say in your question that you wanted to authenticate users. You said that you wanted a winForm that only domain users could use. This will do that, IF your users are logged into a windows machine using their AD credentials. It piggybacks on the current windows user. – wruckie Apr 16 '14 at 21:35
0

Although it is not an ASP.Net app the active directory membership provider will work just fine.

Here is info on how to use this library:

http://msdn.microsoft.com/en-us/library/system.web.security.activedirectorymembershipprovider.aspx

and here is some more information:

http://msdn.microsoft.com/en-us/library/ff650308.aspx

Eric Scherrer
  • 3,328
  • 1
  • 19
  • 34
0

If you want to know how to verify credentials to Active Directory in order to allow AD users in you application, you should check this.

You'll find how to verify the content of your textboxes and verify if username and passowrd matches (directly with the AD).

Community
  • 1
  • 1
Nate B.
  • 942
  • 11
  • 31