Click here to Skip to main content
12,953,937 members (43,661 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I would like to change a login process for a website - the change is to incorporate Active Directory login - How do I go about doing this ??
and should username and password at login accept uppercase and lowercase ???

Posted 27-Jul-12 1:13am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Here you go:
Validation for a single user to the active directory
public static bool User() 
    bool validation;
        LdapConnection lcon = new LdapConnection(new LdapDirectoryIdentifier((string)null, false, false));
        NetworkCredential nc = new NetworkCredential(Environment.UserName, "kals123", Environment.UserDomainName);
        lcon.Credential = nc;
        lcon.AuthType = AuthType.Negotiate;
        lcon.Bind(nc); // user has authenticated at this point, as the credentials were used to login to the dc.
        validation = true;
    catch (LdapException)
        validation = false;
    return validation;

Lists all the users from current domain
public static void getUser()
    DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://" + Environment.UserDomainName);
    string userNames = "";
    string authenticationType="";
    foreach (DirectoryEntry child in directoryEntry.Children)
        if (child.SchemaClassName == "User")
            userNames += child.Name + Environment.NewLine; //Iterates and binds all user using a newline
            authenticationType += child.Username + Environment.NewLine;
    Console.WriteLine("*****************Authentication Type*****************");

Getting user names with groups
public static void fnGetListOfUsers() {
    // set up domain context
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    // find the group in question
    GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "USERS");
    // if found....
    if (group != null)
        // iterate over members
        foreach (Principal p in group.GetMembers())
            Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
            // do whatever you need to do to those members

Getting a particular user details from user's active directory
public static void fnImp() {
    using (var context = new PrincipalContext(ContextType.Domain, Environment.UserDomainName))
        using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
            foreach (var result in searcher.FindAll())
                DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
                if ((string)de.Properties["givenName"].Value == Environment.UserName)
                    //Console.WriteLine("First Name: " + de.Properties["givenName"].Value);
                    //Console.WriteLine("Last Name : " + de.Properties["sn"].Value);
                    //Console.WriteLine("SAM account name   : " + de.Properties["samAccountName"].Value);
                    //Console.WriteLine("User principal name: " + de.Properties["userPrincipalName"].Value);
                    PropertyCollection pc = de.Properties;
                    foreach (PropertyValueCollection col in pc)
                        Console.WriteLine(col.PropertyName + " : " + col.Value);

What you need is all here.
@amitgajjar 28-Jul-12 1:12am
nice 5+
_Amy 28-Jul-12 1:15am
Thank you Amit.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

We would need more specific information to help you with your problem. And yes the login SHOULD accept uppercase and lowercase for the password, if your using a hash algorithm then I don't see why your asking about that.

I suggest you take a look here [^] and here [^]

As a general tip, people like to help you with your coding problems here, not give you a step by step how to. They will ask you to Google your solution, if it is simple they will ridicule you if for ask a stupid question. I learned from experience, Google is your best friend for simple questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,464
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 28 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100