Hi,
I need to check whether a user's password in Active Directory is
expired. I've used Sun's LDAP JDK to retrieve:
maxPwdAge = how long the passwords in AD are valid
lpwdLastSet = when the password was last reset
I have the following code so far:
GregorianCalendar Win32Epoch = new
GregorianCalendar(1601,Calendar.JANUARY,1);
Date Win32EpochDate = Win32Epoch.getTime();
GregorianCalendar Today = new GregorianCalendar();
Date TodaysDate = Today.getTime();
long TimeSinceWin32Epoch = 10000 * (TodaysDate.getTime() -
Win32EpochDate.getTime());
if ((TimeSinceWin32Epoch - lPwdLastSet) >= maxPwdAge)
{
System.out.println("********* EXPIRED **************");
}
else
{
System.out.println("********* NOT EXPIRED **************");
}
But, with the above code, the TimeSinceWin32Epoch value always seems to
be less than 'lPwdLastSet'.
For example, I just did a test where I first reset the password in AD.
Then, I ran my test program and got:
lPwdLastSet = 128014798644537904
TimeSinceWin32Epoch = 128014619454130000
maxPwdAge = -37108517437440
Can anyone tell me what I'm doing wrong?
Thanks,
Jim
Paul Hamaker - 31 Aug 2006 22:16 GMT
Why do you multiply by 10.000 ?
--------------------
Paul Hamaker, SEMM, teaching ICT since 1987
http://javalessons.com
ohaya - 01 Sep 2006 04:19 GMT
Paul,
I'm not sure... it was code that I found on one of the Sun JNDI forums :)...
Actually, I think that I got it working, thanks to another poster on
that forum.
Jim
> Why do you multiply by 10.000 ?
> --------------------
> Paul Hamaker, SEMM, teaching ICT since 1987
> http://javalessons.com