예제 #1
0
        public bool Authenticate(string username, string domain, string password, string ldapUrl)
        {
            try
            {
                var ldapUser = new LDAPUser(username, domain, ldapUrl, password);
                /*checking using LDAP CN authentication*/
                if (AuthenticateCN(ldapUser) || AuthenticateUID(ldapUser))
                {
                    //user is authenticated


                    if (user.Keys.Contains(ldapUser.UserName))
                    {
                        user[ldapUser.UserName] = FindUser(ldapUser.BaseDN, "objectClass=*");
                    }
                    else
                    {
                        user.Add(ldapUser.UserName, FindUser(ldapUser.BaseDN, "objectClass=*"));
                    }
                }
                else
                {
                    throw new Exception("Authentication failed!!!");
                }
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
        bool storeUserDetails(LDAPUser user)
        {
            using (XmlWriter writer = XmlWriter.Create(user.UserName))
            {
                writer.WriteStartDocument();

                writer.WriteStartElement("User");
                writer.WriteElementString("UserName", user.UserName.ToString());
                writer.WriteElementString("Login", Convert.ToString(DateTime.Now));

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            return(true);
        }
예제 #3
0
 bool AuthenticateUID(LDAPUser user)
 {
     try
     {
         var serverId    = new LdapDirectoryIdentifier(user.URL);
         var credentials = new NetworkCredential(user.UID, user.Password);
         var connection  = new LdapConnection(serverId, credentials, AuthType.Basic);
         connection.SessionOptions.ProtocolVersion = 3;//Because we are using LDAPv3 for checking
         connection.Bind();
         connectionAuth = connection;
         user.BaseDN    = user.UID;
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }