Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 ???
 
Thanks
Posted 27-Jul-12 1:13am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
Here you go:
Validation for a single user to the active directory
public static bool User() 
{
    bool validation;
    try
    {
        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("************************Users************************");
    Console.WriteLine(userNames);
    Console.WriteLine("*****************Authentication Type*****************");
    //Console.WriteLine(authenticationType);
}
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);
                    Console.WriteLine();
                    PropertyCollection pc = de.Properties;
                    foreach (PropertyValueCollection col in pc)
                    {
                        Console.WriteLine(col.PropertyName + " : " + col.Value);
                        Console.WriteLine();
                    }
                }
            }
        }
    }
    Console.ReadLine();
}
 

What you need is all here.
--Amit
  Permalink  
Comments
@amitgajjar at 28-Jul-12 1:12am
   
nice 5+
_Amy at 28-Jul-12 1:15am
   
Thank you Amit.
Rate this: bad
good
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.
  Permalink  
v4

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



Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 28 Jul 2012
Copyright © CodeProject, 1999-2014
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