Beispiel #1
0
 public string GetDomainPrefix()
 {
     return(DistinguishedName
            .Split(',')
            .FirstOrDefault(x => x.ToLower().Contains("dc"))
            .Split('=')
            .LastOrDefault()
            .ToUpper());
 }
Beispiel #2
0
 public void Authenticate(string Username, string Password)
 {
     try
     {
         this.DE = new DirectoryEntry(null, Username, Password, AuthenticationTypes.Secure);
         var sss = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
         DirectorySearcher deSearch = new DirectorySearcher(DE);
         deSearch.Filter = "(&(objectClass=user)(sAMAccountName=" + Username + "))";
         SearchResult result = deSearch.FindOne();
         if (result != null)
         {
             this.DE           = new DirectoryEntry(result.Path, Username, Password, AuthenticationTypes.Secure);
             IsAuthenticated   = true;
             FirstName         = GetProperty("givenName");
             MiddleInitial     = GetProperty("initials");
             LastName          = GetProperty("sn");
             UserPrincipalName = GetProperty("UserPrincipalName");
             EmployeeID        = int.Parse(GetProperty("employeeID"));
             //PostalAddress = GetProperty("PostalAddress");
             //MailingAddress = GetProperty("StreetAddress");
             //ResidentialAddress = GetProperty("HomePostalAddress");
             Title = GetProperty("Title");
             //HomePhone = GetProperty("HomePhone");
             //OfficePhone = GetProperty("TelephoneNumber");
             //Mobile = GetProperty("Mobile");
             //Fax = GetProperty("FacsimileTelephoneNumber");
             Email             = GetProperty("mail");
             Url               = GetProperty("Url");
             this.Username     = GetProperty("sAMAccountName");
             DistinguishedName = GetProperty("DistinguishedName");
             //Company = GetProperty("Company");
             Department  = GetProperty("Department");
             DisplayName = FirstName + ((MiddleInitial.Trim() != string.Empty) ? " " + MiddleInitial.Trim() + "." : string.Empty) + " " + LastName;
             Groups.Clear();
             for (int i = 0; i <= DE.Properties["memberOf"].Count - 1; i++)
             {
                 string s = GetProperty("memberOf", i);
                 if (s.IndexOf("OU=CPL Systems") != 0)
                 {
                     string[] x = s.Split(',')[0].Split('=');
                     Groups.Add(x[1]);
                 }
             }
             OU = DistinguishedName.Split(',')[1].Replace("OU=", "");
         }
     }
     catch
     {
         //Exception = ex;
         Clear();
     }
 }