C# user app

Posted on 2014-04-12
Last Modified: 2014-04-14
Hi guys ,

I would like to know it there is some possibility to create login for users that authenticate with active directory like LDAP.

For now I'm using sql database and wrote this code for authenticate users:

private void button1_Click(object sender, EventArgs e)
                string Conn = "Data Source=srv-db-02;Initial Catalog=rmsmasterdbtest;Persist Security Info=True;User ID=test;Password=masterB4";
                SqlConnection Myconn = new SqlConnection(Conn);
                SqlCommand SelectCommand = new SqlCommand("select * from rmsmasterdbtest.dbo.UserLogin where Fname='" + this.txtUsernamelogin.Text + "' and passw='" + this.txtpass_Login.Text + "' ;", Myconn);

                SqlDataReader reader;
                reader = SelectCommand.ExecuteReader();
                int count = 0;
                while (reader.Read())
                    count = count + 1;
                if (count == 1)
                    frmControlusers f2 = new frmControlusers("Welcome," +txtUsernamelogin.Text);
                else if (count > 1)
                    MessageBox.Show("Duplicate username and password.....access denied");
                    MessageBox.Show("Username and Password is Not Correct");
            catch (Exception ex)

Open in new window

Question by:Moti Mashiah
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Assisted Solution

aces4all00 earned 250 total points
ID: 39996386
Yes you can use LDAP based authentication against an AD domain controller.  See for an example

Author Comment

by:Moti Mashiah
ID: 39996427
Thanks for this article but my app is windows form application.
LVL 10

Accepted Solution

Korbus earned 250 total points
ID: 39997574
looks like you want to include and use this C# library for AD authentication: System.DirectoryServices

I actually found it in the link Peter provided, which creates a kind of wrapper around it (which I would copy/paste and use in c#), and then uses it in aspx.
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

by:Moti Mashiah
ID: 39997646
I'm using windows application form and the code peter sent is not working in this situation
LVL 10

Expert Comment

ID: 39997725
Check out the IsAuthenticated function in the "Write the authentication code" section, and the explanation of it, below the code.  This is an example of how to use the System.DirectoryServices library for AD authentication in c#.  You can also look up the library on MSDN for more details.

Will need more detail on HOW it's not working to help further.

Author Closing Comment

by:Moti Mashiah
ID: 39999815
partly helped

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question