Active Directory Password

fredriko

Active member
Joined
Jun 3, 2004
Messages
35
Programming Experience
10+
I am writing a basic active directory integration into my latest application and am struggling. I've found code that will allow me to validate users and change their passwords but I'm struggling to find how to identify how many days a users has left to change their password.
For example, on our server at work we must change our passwords every 30 days or so. I want to be able to query active directory against a given users and identify that they have 14 days left (or however many) to change their password. Does anybody know how I can do this?
 
Hi Fredriko,

Try out this :

Public Function GetUserNames As String()
Dim mydirectory As DirectoryEntry = New DirectoryEntry("LDAP:\\Yourpath")
dim mysearcher As DirectorySearcher = New DirectorySearcher(mydirectory)
'Search for the user whose account will expire ( 0 or 9223372036854775807 means that account will never expire
mysearcher.Filter = ("(objectClass= user)( (Not accountExpires = 0) Or (Not accountExpires = 9223372036854775807)")
Dim result As SearchResult
Dim resultcount As Integer = mysearcher.FindAll.Count

If resultcount > 0 Then
Dim usernames(resultcount - 1) As String
Dim index As Integer = 0

For Each result In mysearcher.FindAll
If index <= usernames.Length - 1 Then
Dim username As String = result.GetDirectoryEntry.Name.ToString
usernames(index) = username
index += 1
End If
Array.Sort(usernames)
Return usernames
Else
Return Nothing
End If
End Function
 
Back
Top