Solved

C# user app

Posted on 2014-04-12
6
225 Views
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)
        {
            try
            {
                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;
                Myconn.Open();
                reader = SelectCommand.ExecuteReader();
                int count = 0;
                while (reader.Read())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    this.Hide();
                    frmControlusers f2 = new frmControlusers("Welcome," +txtUsernamelogin.Text);
                    f2.ShowDialog();
                }
                else if (count > 1)
                {
                    MessageBox.Show("Duplicate username and password.....access denied");
                }
                else
                    MessageBox.Show("Username and Password is Not Correct");
                Myconn.Close();
            }
            catch (Exception ex)
            { 
                MessageBox.Show(ex.Message);
            }

Open in new window

0
Comment
Question by:Moti Mashiah
  • 3
  • 2
6 Comments
 
LVL 3

Assisted Solution

by:aces4all00
aces4all00 earned 250 total points
ID: 39996386
Yes you can use LDAP based authentication against an AD domain controller.  See http://support.microsoft.com/kb/316748 for an example
0
 
LVL 1

Author Comment

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

Accepted Solution

by:
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.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

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

Expert Comment

by:Korbus
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.
0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 39999815
partly helped
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
designing in object programming 12 94
EF5: Question about Metadata Artifact Processing 4 22
Hey!! 5 37
VS2013 publish C# application Created folder -- where is it??? 10 27
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

840 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