Solved

compare two dates in script

Posted on 1998-06-29
6
477 Views
Last Modified: 2012-05-05
I need to write a script that will notify users of their password expiration after logging in to to
a Win95 client. The text file with the user's password expiration date will reside in their
$HOME directory. The script will reside in the Windows startup folder. The script should
compare the date in the file with the system date, and print a "Password will expire in x days"
message if the date in the file is less than 5 days than the current (system) date.
The script will also need to update the file in the user's $HOME directory with the new
password expiration date after the user changes his or her password.
Can I accomplish this with perl?  I would appreciate some source code to help me write
this solution. I installed Perl for Win95 and I want to start using its functionality, but I think I
need some help to get off the ground. I am digesting all the documentation now, but I have to
write this solution now!

Thanks in advance for your help!
0
Comment
Question by:denmarkw
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1208241
What's the format of the date in the text file?
0
 
LVL 2

Accepted Solution

by:
tpryor earned 200 total points
ID: 1208242
answer to follow...
0
 
LVL 2

Expert Comment

by:tpryor
ID: 1208243
OK , there are a couple parts to your question lets take them one at a time.

1) Read the file line by line looking for a match...

open(FILE, "pwd/file/path") || print couldnt open the file, $!;
while (<FILE>) {
      if ($_ =~ /$user/) { # be as specific as neeeded
            #### check dates todays vs pwd

2) Logic to check dates...

# I recomend storing the date as yymmdd
# makes for easy comparison
# use the date.pl library to help you format the dates
# i will give you the url for it

($user, $pwd, $user_date) = split(/\/, $_);
# this will split the matched record into fields

$today_julian_day = &today();
# this will give me the julian date for today

$days_ago = 30;
# freshness date

($month,$day,$year,$weekday) = &jdate($julian_day - $days_ago)
# this will format it into something a human can understand

$bench_mark_date = sprintf("%02d%02d%02d", $year, $month, $day);
# this will make it easy to compare

if($user_date <= $bench_mark_date){

#### Tell user to change pwd
#### close file
#### exit program

}else{

#### continue with program
}

3) if the user must change pwd

### present login screen with new pwd option

same as no.1, open pwd file read line by line when you find him split up the line change the password field write back to file.
make sure you look the file when writing to it.

I didnt go into to many details about reading the file and writeing because that is pretty basic. you can go to www.perl.com
and get a ton of info about that kind of stuff. The text file is simple just a file where each line is a record with each ellement in the record seperated by something ie
tom|password|19980629
Im not sure of your programming level so Ill leave it at that, i dont wont to bore you with the basics if you already know them.

The tricky part is dealing with dates, as long as your system deals with julian dates (most do) this code will do the trick.
I will give you the url to date.pl to use it make sure you type
use date.pl
in your cgi before you call the time/date functions. And that you save the date.pl library in the same dir as your cgi.
 should be all set.

the date.pl url is...
http://www.extropia.com/Scripts/Source/Library/date.pl.txt

GL
t

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:alamo
ID: 1208244
># I recomend storing the date as yymmdd
># makes for easy comparison

And people are still amazed that software produced within the past few years, let alone today, has a Y2K problem... (Although in this case it won't fail catastrophically, it's so easy to do it right that you should use a 4 digit year).

I am not criticizing you, tpryor, just pointing out how embedded 2 digit years are in most people's thinking, leading to a $trillion problem.
0
 
LVL 2

Expert Comment

by:tpryor
ID: 1208245
cool!


BTW the code example actually produces a 4 digit year.
<gr>
t

0
 

Author Comment

by:denmarkw
ID: 1208246
Thanks for your comments!
tpryor:
Please lets clarify some of the code. I am just a beginner when it comes to Perl!
So I would appreciate any details for clarity.
First, the compare file on the client PC only has
the password expiration date.  This file has to be created and populated with the
system date after the first reboot which will force the user to change his or her Solaris
password. How do I create this file and put the current Win95 system date in it? How can
I control the date format?
Second, is the split necessary if only a date is in the compare file?
Third, why do we subrtract 30 days? After the first system reboot the script should force
a password change and update the expiration date by adding 60 days to the current date
and update the compare file on the client.  Any subsequent reboot should only compare the difference between the current system date and the date in the compare file.
If the compare date is less than the system date by 5 days or less, a window should pop
up on the Win95 client notifying the user of the number of days until expiration and should give the user the option to change his or her password from the pop-up window.
How can I create a GUI with Perl for win32?
Fourth, I need to call the Win95 "telnet" executable after the first reboot and whenever the
compare condition is met. How do I make system calls in Perl?
Thanks in advance for your assistance experts!

Knowledge is power, but it is only useful if it is shared!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now