Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unix Password Age

Posted on 2010-09-20
7
Medium Priority
?
1,769 Views
Last Modified: 2013-12-04
Ok this is probably a very easy question, but I have looked all over EE and google, but I cant seem to find the answer.

I am trying to calculate the password age of a Unix user.  I can get the age value if i use the /etc/shadow file and I have the following results:

johndoe:PaSsWoRdxye7d:13062:30:100:10:inactive:expire:
^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | | |
username:password:lastchg:min:max:warn:inactive:expire:flag

But how do i take the "13062" and calculate it to determine the actual password date/age.

I read some where that its the "13062" value is the amount of days since Jan 1 1970.
Is this correct?
0
Comment
Question by:nakoz69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:jimmyray7
ID: 33721127
That's correct.  UNIX uses epoch time, which started Jan 1 1970.
0
 
LVL 8

Expert Comment

by:jimmyray7
ID: 33721159
This thread may be helpful in regards to scripting with the password age: http://www.unix.com/shell-programming-scripting/33854-check-password-age.html
0
 
LVL 1

Author Comment

by:nakoz69
ID: 33721175
So how do i calc the "13062" from 1/1/1970?
0
Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

 
LVL 8

Expert Comment

by:jimmyray7
ID: 33721331
On a *nix OS, date +%s will give you the number of seconds since epoch.  Divide by 60 to get minutes, again by 60 to get hours, then by 24 to get days.  Then you can compare that to what shows up in the password file to see how old the password is.
0
 
LVL 1

Author Comment

by:nakoz69
ID: 33721405
When i try:

# date %s
I get:

date: bad conversion

BTW I forgot to say that I am running the following version of SunOS:
5.8 Generic
0
 
LVL 8

Accepted Solution

by:
jimmyray7 earned 2000 total points
ID: 33721455
Ah, Sun/Solaris date command doesn't support those flags.  I didn't know that.  Well, you can use perl or another scripting language of your choice, or do what this guy did: http://solarisjedi.blogspot.com/2006/06/solaris-date-command-and-epoch-time.html
0
 
LVL 1

Author Comment

by:nakoz69
ID: 33721620
Ok so i finally got it figured out.  Thanks Jimmy for all the help:

Process to convert the "lastchg" field from the "shadow" file to an actual day you need to use the following Steps:

# cat /etc/shadow
- you get the following result:

root:PaSsWoRd:14797::::::

- the "14797" is the "lastchg" value
- this is the epoch time value since the password was changed (unix uses EPOCH time which is time since 01/01/1970)
- this value is in days so we need to convert it to minutes to get a date time

Formula:
= "lastchg"*(hrs in a day)*(minutes in a day)
= 14797*24*3600
= 1278547200

We can now take this value and plug it into excel using the following formula
= (EPOCH_Value/sec in a day)+(days from 1900 to 1970)
= ((1278547200/86400)+25569)
= 40366
*Note: That excel actually starts from 1/1/1900 so you have to account for the 70 year difference in time
since EPOCH time starts at 1/1/1970
- which is why you add the 25569


You can now use the date/time format in excel and see the current date.

OR

You can take the easy way out.

Since the "Lastchg" result is actually in days there is no need to convert from days to seconds back to days
- you can plug the following formula into excel and just use the date/time format to see the last change date

= ("lastchg"+(days from 1900 to 1970)
= 14797+25569
= 40366
When formatted in excel this turns out to be 7/7/10 12:00AM

Enjoy!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
OfficeMate Freezes on login or does not load after login credentials are input.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

721 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