Link to home
Start Free TrialLog in
Avatar of ubsjmg
ubsjmg

asked on

Sample Code to Compute Password Expiration for Active Directory

I need to write some JNDI code that determines the date on which an Active Directory user's password will expire.  If anyone could point me to an example or code snippet I would really appreciate it.  In AD the pwdLastSet attribute stores the number of elapsed seconds sin Jan 1, 1970.  I have written code to get the value convert it to a long and pass the value to the java.util.Date constructor.  I am running into a problem when I try to multiply the value retrived from AD * 1000 to get the elapsed milliseconds.  When I do the multiplication I receive a negative number.  Anyway any help would be greatly appreciated.

Thanks in advance.
Avatar of Andrey_Kulik
Andrey_Kulik

Hi
could you sent your source?

May be it's simple problem: long millis = (long)pwdLastSet * (long)1000;

Best regards
Andrey
Avatar of ubsjmg

ASKER

Hi Andre,
     Here is my code snippet.  The value I retrieve from AD is 126640664549531250.  

if(attrId.equalsIgnoreCase("pwdLastSet")){
for(Enumeration vals = attr.getAll(); vals.hasMoreElements();){
 String lvalue = (String)vals.nextElement();
 System.out.println("Number of Seconds Un Converted: " +   lvalue);
 long lNumSeconds = Long.parseLong(lvalue);
 System.out.println("Number of Milliseconds: " + (lNumSeconds * 1000));
 Date ldateValue = new Date(lNumSeconds);
  DateFormat df1 = DateFormat.getDateInstance   format.SHORT);                    
  System.out.println(df1.format(ldateValue));
 }//for
}//if
Hi ubsjmg,
your AD's value is too big (Nov 26, 4015052)
and 126640664549531250 sec * 1000 = ~4015052000 years

Check your AD's repository ... may be 126640664549531250 is default UNDEFINED value ?

It looks like 126640664549531250 is two concatenated strings 126640664sec + 549531250sec...

other ideas?

Best regards
Andrey
Avatar of ubsjmg

ASKER

I agree.  I wrote some code that returned the number of elapsed milliseconds since Jan 1, 1970 and found the value to be much smaller.  I have asked a question of our Microsoft contact to tell me what that Value represents.
Avatar of girionis
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- To be PAQ'ed and points refunded

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of PashaMod
PashaMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial