Logging in and out...

D

Daniel Bass

Hi,

I've a situation where my application has to manage usernames and passwords,
and after a certain amount of idle time, the application will log the
current user out, (assuming they've left without logging out manually) and
prompt for a new log in.

Is there any way to do this, without having to call a reset method on the
timer i've got running in just about every method...
i.e. a global method holds a countdown of idle time, that is reset to my
timeout time everytime the user presses a key, clicks a button, so that when
the idle timer reaches zero, there's been no activity and it logs the user
out.

Is there a cleaner way about this?

Thanks.
Daniel
 
N

Nicholas Paldino [.NET/C# MVP]

Daniel,

I had to do this in VB6, but you should be able to implement the same
solution in your application. First, what you have to do is place a timer
in your application (your main form would do just fine). The resolution of
the timer is how much of a leeway you are willing to give the user for that
threshold (for example, if your threshold is 30 seconds, but it's ok if the
user takes 35, then set the timer resolution for five seconds).

Additionally, you would have a DateTime variable which is easily
accessible. Initialize this instance to the current time when the
application starts (or is finished initializing, basically, when you enable
the timer).

Then, create a class that implements IMessageFilter and pass an instance
of the implementation to the static AddMessageFilter method on the
Application class. Your implementation is going to look for any events
(mouse or keyboard) which are sent to the application. When you see the
windows message representing the event, set the DateTime variable to the
current time (or tickcount).

Then, in the timer event, you check the TimeSpan between Now (when the
timer fired), and the variable that is stored. If the TimeSpan is more than
your threshold, then you can log the user out.

In VB6, I did this with keyboard and mouse hooks for the current
process, and you can go that route in .NET, but it might be easier to do
with the IMessageFilter interface.

Hope this helps.
 
D

Daniel Bass

Thanks, that sounds the sort of things I'm looking for...

one bit of information I left out is this is for a c# app, but it's for a
Windows Mobile 2003 platform... will that make a difference?


Nicholas Paldino said:
Daniel,

I had to do this in VB6, but you should be able to implement the same
solution in your application. First, what you have to do is place a timer
in your application (your main form would do just fine). The resolution of
the timer is how much of a leeway you are willing to give the user for that
threshold (for example, if your threshold is 30 seconds, but it's ok if the
user takes 35, then set the timer resolution for five seconds).

Additionally, you would have a DateTime variable which is easily
accessible. Initialize this instance to the current time when the
application starts (or is finished initializing, basically, when you enable
the timer).

Then, create a class that implements IMessageFilter and pass an instance
of the implementation to the static AddMessageFilter method on the
Application class. Your implementation is going to look for any events
(mouse or keyboard) which are sent to the application. When you see the
windows message representing the event, set the DateTime variable to the
current time (or tickcount).

Then, in the timer event, you check the TimeSpan between Now (when the
timer fired), and the variable that is stored. If the TimeSpan is more than
your threshold, then you can log the user out.

In VB6, I did this with keyboard and mouse hooks for the current
process, and you can go that route in .NET, but it might be easier to do
with the IMessageFilter interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Daniel Bass" <DanielBass TAKE at OUT CAPS WORDS Postmaster.co.uk> wrote in
message news:[email protected]...
Hi,

I've a situation where my application has to manage usernames and passwords,
and after a certain amount of idle time, the application will log the
current user out, (assuming they've left without logging out manually) and
prompt for a new log in.

Is there any way to do this, without having to call a reset method on the
timer i've got running in just about every method...
i.e. a global method holds a countdown of idle time, that is reset to my
timeout time everytime the user presses a key, clicks a button, so that when
the idle timer reaches zero, there's been no activity and it logs the user
out.

Is there a cleaner way about this?

Thanks.
Daniel
 
D

Daniel Bass

Nicholas,

I've looked into this, but don't understand how i can create a class that
implements an unmanaged interface.

Dan.

Daniel Bass said:
Thanks, that sounds the sort of things I'm looking for...

one bit of information I left out is this is for a c# app, but it's for a
Windows Mobile 2003 platform... will that make a difference?


message news:[email protected]...
Daniel,

I had to do this in VB6, but you should be able to implement the same
solution in your application. First, what you have to do is place a timer
in your application (your main form would do just fine). The resolution of
the timer is how much of a leeway you are willing to give the user for that
threshold (for example, if your threshold is 30 seconds, but it's ok if the
user takes 35, then set the timer resolution for five seconds).

Additionally, you would have a DateTime variable which is easily
accessible. Initialize this instance to the current time when the
application starts (or is finished initializing, basically, when you enable
the timer).

Then, create a class that implements IMessageFilter and pass an instance
of the implementation to the static AddMessageFilter method on the
Application class. Your implementation is going to look for any events
(mouse or keyboard) which are sent to the application. When you see the
windows message representing the event, set the DateTime variable to the
current time (or tickcount).

Then, in the timer event, you check the TimeSpan between Now (when the
timer fired), and the variable that is stored. If the TimeSpan is more than
your threshold, then you can log the user out.

In VB6, I did this with keyboard and mouse hooks for the current
process, and you can go that route in .NET, but it might be easier to do
with the IMessageFilter interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Daniel Bass" <DanielBass TAKE at OUT CAPS WORDS Postmaster.co.uk> wrote in
message news:[email protected]...
Hi,

I've a situation where my application has to manage usernames and passwords,
and after a certain amount of idle time, the application will log the
current user out, (assuming they've left without logging out manually) and
prompt for a new log in.

Is there any way to do this, without having to call a reset method on the
timer i've got running in just about every method...
i.e. a global method holds a countdown of idle time, that is reset to my
timeout time everytime the user presses a key, clicks a button, so
that
when
the idle timer reaches zero, there's been no activity and it logs the user
out.

Is there a cleaner way about this?

Thanks.
Daniel
 
D

Daniel Bass

never mind, it's part of System.Windows.Forms!

Daniel Bass said:
Nicholas,

I've looked into this, but don't understand how i can create a class that
implements an unmanaged interface.

Dan.

"Daniel Bass" <DanielBass TAKE at OUT CAPS WORDS Postmaster.co.uk> wrote in
message news:[email protected]...
Thanks, that sounds the sort of things I'm looking for...

one bit of information I left out is this is for a c# app, but it's for a
Windows Mobile 2003 platform... will that make a difference?


message news:[email protected]...
Daniel,

I had to do this in VB6, but you should be able to implement the same
solution in your application. First, what you have to do is place a timer
in your application (your main form would do just fine). The
resolution
of
the timer is how much of a leeway you are willing to give the user for that
threshold (for example, if your threshold is 30 seconds, but it's ok
if
the
user takes 35, then set the timer resolution for five seconds).

Additionally, you would have a DateTime variable which is easily
accessible. Initialize this instance to the current time when the
application starts (or is finished initializing, basically, when you enable
the timer).

Then, create a class that implements IMessageFilter and pass an instance
of the implementation to the static AddMessageFilter method on the
Application class. Your implementation is going to look for any events
(mouse or keyboard) which are sent to the application. When you see the
windows message representing the event, set the DateTime variable to the
current time (or tickcount).

Then, in the timer event, you check the TimeSpan between Now (when the
timer fired), and the variable that is stored. If the TimeSpan is
more
than
your threshold, then you can log the user out.

In VB6, I did this with keyboard and mouse hooks for the current
process, and you can go that route in .NET, but it might be easier to do
with the IMessageFilter interface.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Daniel Bass" <DanielBass TAKE at OUT CAPS WORDS Postmaster.co.uk>
wrote
in
message Hi,

I've a situation where my application has to manage usernames and
passwords,
and after a certain amount of idle time, the application will log the
current user out, (assuming they've left without logging out
manually)
and
prompt for a new log in.

Is there any way to do this, without having to call a reset method
on
the
timer i've got running in just about every method...
i.e. a global method holds a countdown of idle time, that is reset
to
my the
user
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top