473,396 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get AD user password expire date?

Trying to get the user password expire date from AD, but there is no such
field.
What I could get is the PasswordLastChanged property.

Is there anyway I could calculate the date or something?

Regards,
Bryan
Nov 16 '05 #1
5 28234
The pwdLastSet property is a large integer holding the number of 100ns
intervals since 1601 or something - also known as a FILETIME value.

The DateTime class has a "FromFileTime()" method that will convert that into
a date. Watch out for UTC / local time differences.

In order to see when the password will expire you also need to read the
default domain policy to find out how often a user must change a password.

If you use the WinNT ADSI provider instead of the LDAP ADSI provider you
could get the "PasswordExpirationDate" property which will calculate the
date for you (never tested this though)
Arild

"Bryan Yeo" <br******@commerce.com.sg> wrote in message
news:O3****************@tk2msftngp13.phx.gbl...
Trying to get the user password expire date from AD, but there is no such
field.
What I could get is the PasswordLastChanged property.

Is there anyway I could calculate the date or something?

Regards,
Bryan

Nov 16 '05 #2
Btw... found this article which may help:
http://msdn.microsoft.com/library/de...ng09102002.asp
Arild

"Arild Bakken" <ar*****@hotmail.com> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
The pwdLastSet property is a large integer holding the number of 100ns
intervals since 1601 or something - also known as a FILETIME value.

The DateTime class has a "FromFileTime()" method that will convert that into a date. Watch out for UTC / local time differences.

In order to see when the password will expire you also need to read the
default domain policy to find out how often a user must change a password.

If you use the WinNT ADSI provider instead of the LDAP ADSI provider you
could get the "PasswordExpirationDate" property which will calculate the
date for you (never tested this though)
Arild

"Bryan Yeo" <br******@commerce.com.sg> wrote in message
news:O3****************@tk2msftngp13.phx.gbl...
Trying to get the user password expire date from AD, but there is no such field.
What I could get is the PasswordLastChanged property.

Is there anyway I could calculate the date or something?

Regards,
Bryan


Nov 16 '05 #3
I have tried the microsoft and try to convert the codes to C#, this is
what I have:

IADsLargeInteger fds2 =
(IADsLargeInteger)searchentry2.Properties["maxPwdAge"].Value;
double ONE_HUNDRED_NANOSECOND = 10^-7; //.000000100;
int SECONDS_IN_DAY = 86400;
int fgd = (int)fds2.HighPart;
int fgd2 = (int)fds2.LowPart;
double dblMaxPwdNano = Math.Abs((int)fds2.HighPart * 2^32 +
(int)fds2.LowPart);
double dblMaxPwdSecs = (int)dblMaxPwdNano * .000000100;
double dblMaxPwdDays = (int)dblMaxPwdSecs / SECONDS_IN_DAY;

But there is something either wrong with the code or with the
calculation, I got a zero.
And which policy does the maxpwdage taken from? local security policy,
domain security policy or domain controller policy?

Regards
Bryan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Try this for domain policy enforced pwd. aging.

public static void Main() {
long maxAge;
// Get maxPwdAge from domain
using(DirectoryEntry domain = new
DirectoryEntry("LDAP://domain/DC=xxxx,DC=xxxx,DC=xxx", "xxx\\administrator",
"ppppp"))
{
LargeInteger liMaxAge =domain.Properties["MaxPwdAge"].Value as
LargeInteger;
maxAge = (((long)(liMaxAge.HighPart) << 32) + (long) liMaxAge.LowPart);
// SHOULD be a negative value !!!
}
// Get pwdlast set for user (here administrator)
DirectoryEntry user = new
DirectoryEntry("LDAP://domain/CN=administrator,cn=users,DC=celeb,DC=w2kdom,DC=co m",
"xxx\\administrator", "xxxxx");
LargeInteger li = user.Properties["pwdLastSet"].Value as LargeInteger;
long expDate = (((long)(li.HighPart) << 32) + (long) li.LowPart) - maxAge;
// !!! maxAge is negative number!!!
LiToDate(expDate);
}
}
static void LiToDate(long date)
{
Console.WriteLine(date);
string dt = DateTime.FromFileTime(date).ToString(); // To file time
Console.WriteLine("DATE = {0:D}" ,dt); // show pwd expiry date
}
....

Willy.

"Bryan Yeo" <br******@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have tried the microsoft and try to convert the codes to C#, this is
what I have:

IADsLargeInteger fds2 =
(IADsLargeInteger)searchentry2.Properties["maxPwdAge"].Value;
double ONE_HUNDRED_NANOSECOND = 10^-7; //.000000100;
int SECONDS_IN_DAY = 86400;
int fgd = (int)fds2.HighPart;
int fgd2 = (int)fds2.LowPart;
double dblMaxPwdNano = Math.Abs((int)fds2.HighPart * 2^32 +
(int)fds2.LowPart);
double dblMaxPwdSecs = (int)dblMaxPwdNano * .000000100;
double dblMaxPwdDays = (int)dblMaxPwdSecs / SECONDS_IN_DAY;

But there is something either wrong with the code or with the
calculation, I got a zero.
And which policy does the maxpwdage taken from? local security policy,
domain security policy or domain controller policy?

Regards
Bryan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #5
Thanks for the code, it's a great help.
Trying to figure out for days already.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Geoff Muldoon | last post by:
Hi all, Help please. Environment: Unix (Tru64) / Apache / PHP4.0.6 / Oracle8i Establish connection to Oracle: for ($I=0; $I<$max_attempts; $I++) {
15
by: Joshua Beall | last post by:
Hi All, What is the best way to use a cookie to remember a logged in user? Would you store the username and password in two separate cookies? Should the password be plain text? Hashed? Not...
0
by: Bob Rivers | last post by:
Hi, I have an application that uses jdbc (9.2.0.3/classes12) to connect to an Oracle db (9i). It works fine, except when the user password is going to expire. Let me try to explain (sorry my...
7
by: What-a-Tool | last post by:
How does the expire date work setting it server side with asp. I know with javascript setting it client side it will be set to the clients local time, and therefore expire when the clients local...
0
by: Kenneth Keeley | last post by:
Hi, How can I do the below code in ASP.Net as I wish to provide an indication to my staff on our Intranet site of when they will need to change there password. On Error Resume Next Const...
2
by: Fabrice | last post by:
Hello, I 'would like to build a system (based on database, not SqlServer but MySQL) to permit only one session per user. I'm using a form athentication. My Solution : --------------- When...
23
by: Phil Powell | last post by:
// OBTAINED FROM http://www.javascripter.net/faq/settinga.htm // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY AND THUS EXPIRE function setCookie(name, value, days, docObj)...
32
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
3
by: swetha123 | last post by:
hello, I don't know how to use cookies please help me in this I am using the dream weaver cs4 I designed the navigation bar to my page using dream weaver cs4 navigation bar contains...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.