Solved

LDAP Query - Password Expires

Posted on 2007-11-30
5
2,738 Views
Last Modified: 2011-09-20
Can you tell me why these dont work?

        private TimeSpan GetMaxPasswordAge()
        {
            DirectoryEntry entry = new DirectoryEntry("LDAP://SERVER1:3268");
            entry.AuthenticationType = AuthenticationTypes.Secure;

            DirectorySearcher searcher = new DirectorySearcher(entry, "(objectClass=*)", null, SearchScope.Base);
            SearchResult result = searcher.FindOne();
            TimeSpan maxPwdAge = TimeSpan.MinValue;
            if (result.Properties.Contains("maxPwdAge"))
                maxPwdAge = TimeSpan.FromTicks((long)result.Properties["maxPwdAge"][0]);
           
            return maxPwdAge.Duration();
        }

//-------------------
                    searcher = new DirectorySearcher(entry, filter, new string[] { "maxpwdage" });
                    result = searcher.FindOne();
                    if (result.Properties["pwdLastSet"].Count > 0)
                    {
                        if (result.Properties["pwdLastSet"][0].ToString() != "")
                            pwdLastSet = result.Properties["pwdLastSet"][0].ToString().ToLower();
                    }
0
Comment
Question by:Rowdyone52
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20383077
are you getting an exception now? what problems are u having?
0
 

Author Comment

by:Rowdyone52
ID: 20383097
The value for result.Properties["maxPwdAge"].Count  and  result.Properties["pwdLastSet"].Count  are always zero.  I dont get an exception.
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20383136
List out all the properties and see if this property exists in the Search Result properties.
It may not be available or u might have been using the wrong property name
ResultPropertyCollection myResultPropColl;

myResultPropColl = mySearchResult.Properties;

Console.WriteLine("The properties of the " + 

                  "'mySearchResult' are :");

foreach( string myKey in myResultPropColl.PropertyNames)

{

   string tab = "    ";

   Console.WriteLine(myKey + " = ");

   foreach( Object myCollection in myResultPropColl[myKey])

   {

      Console.WriteLine(tab + myCollection);

   }

}

Open in new window

0
 

Author Comment

by:Rowdyone52
ID: 20383669
it isnt available, but I am looking all over the net and it should be.  I cannot figure out why I can't access that property name.
0
 
LVL 21

Accepted Solution

by:
surajguptha earned 500 total points
ID: 20383701
I dont know if this would help you but posting it anyways
http://msdn2.microsoft.com/en-us/library/ms974598.aspx
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now