A/D/ Authentication for Windows Based App

hi,

I have a Windows based application (C# - VS2010) and I would like to authenticate users against active directory. My application talks to MS SQL Server on the back-end and the followings are required when user(s) make any changes to the database:
CreatedBy ==> User name
CreatedByUserId ==> S-1-5-91-4072499873-234284423-3289563812-2580
ModifiedByUserId  ==> looks like something like this from A/D (K-1-5-21-4072499873-234384823-3289563812-2580)

I have not been able to find anything, all examples seems to be for ASP.NET and nothing for Windows based app.

does anyone have a good example on how to build a logon page form using Visual Studio 2010 and .NET framework 4.0?

Thanks
smaguireAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vikram Singh SainiSoftware Engineer cum AD DeveloperCommented:
I have not been able to find anything, all examples seems to be for ASP.NET and nothing for Windows based app.

I am not clear about your question. What I am able to interpret is that you are trying to authenticate user from AD. Please share more details how.
smaguireAuthor Commented:
I want to have a logon screen where users enter their domain\username and domain password in order to gain access to my application.

once successful logon, users will be able to add/delete or modify records, each modified record must have the logged on user name saved in it for tracking purposes.
I am using Windows forms application and not web based application

thank you
smaguireAuthor Commented:
I found this code which which works fine, credit to:
http://stackoverflow.com/questions/11665204/how-to-login-to-active-directory


//NOTE: This can be made static with no modifications
public bool ActiveDirectoryAuthenticate(string username, string password)
{
    bool result = false;
    using (DirectoryEntry _entry = new DirectoryEntry())
    {
        _entry.Username = username;
        _entry.Password = password;
        DirectorySearcher _searcher = new DirectorySearcher(_entry);
        _searcher.Filter = "(objectclass=user)";
        try
        {
            SearchResult _sr = _searcher.FindOne();
            string _name = _sr.Properties["displayname"][0].ToString();
            result = true;
        }
        catch
        { /* Error handling omitted to keep code short: remember to handle exceptions !*/ }
    }

    return result; //true = user authenticated!
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

it_saigeDeveloperCommented:
Are you wanting to impersonate or login as the user for anything or just be able to confirm that their credentials are correct?

It sounds like you need their credentials so that you can have their domain attributes/properties available for recording purposes.  If that's the case, is there any reason to believe that you just can't use the current user identity?

-saige-
bbaoIT ConsultantCommented:
better to post your answer and accept it as the solution. you may also assign points to the comments that ever helped you in anyway.
bbaoIT ConsultantCommented:
BTW, below is an official how-to article about ASP.NET authentication form against AD. example codes are included.

How To: Use Forms Authentication with Active Directory in ASP.NET 2.0
https://msdn.microsoft.com/en-us/library/ff650308.aspx
smaguireAuthor Commented:
got it working myself
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.