You can do two things here to prevent such cases

1) Specify a TimeOut delay that will 'disconnect' the user after a that
given period of idle time
2) Store also some information about the terminal... if a user is trying to
login and his name is found in table ManageUsers and his terminal match the
stored terminal information you should probably grant him access, but if the
same user is trying to access from another terminal someone must be messing
around probably... I know this isn't a good way to solve things but it is a
way...

    As for the point 1 it might help you a lot but not completely

Vahan

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] Behalf
Of soonhuat ong
Sent: Wednesday, June 08, 2005 2:59 AM
To: [email protected]
Subject: Re: [delphi-en] Re: Restrict only 1 terminal login for 1 user


Hi,

Thanks for your comments. One more question here, when the user logout from
the terminal, I'll delete it from the ManageUsers table. What about if
there's an electrical/power failure or other cause ?? That particular user
record won't deleted, so next time when he/she try to login the "Exception
TooManyLogins" will be executed. Thanks again.

Mick Arundell <[EMAIL PROTECTED]> wrote:

Message: 11
   Date: Tue, 7 Jun 2005 00:40:37 -0700 (PDT)
   From: soonhuat ong <[EMAIL PROTECTED]>
Subject: Restrict only 1 terminal login for 1 user

Is there any way for me to restrict that one user can
only allow to
login 1 terminal/PC . Means that if they try to login
to other PC, the
system will provide them with the message : "Login
failure". For your
information, i'm using Interbase 6. Thx

Soonhuat,
1)  Drop Interbase 6 use Firebird
2)  I assume you want to limit each user to one login
at a time.

Solution,
Create table ManageUsers(
UName char(32),
constraint ManageUsers_Pk primary key (Uname)
);

create Exception TooManyLogins 'Only one login at a
time';
set term ^ ;
create trigger ManageUsers_Bi for ManagerUsers
active
before insert
position 0
as
begin
  new.UName = Current_User;
end

set term ; ^

On your datamodule have an sql object with the code
insert into ManageUsers
(UName)
values
('user') /* any value here since it will be replaced
by the trigger*/


in your client application have a routine that runs
after connect
procedure TDataModule.AfterDbConnect(Sender : TObject)
begin
  with ManageUsersQ do begin
    try
      Transaction.Active := true;
      if not prepared then prepare;
      ExecQuery;
      if Transaction.InTransaction then
Transaction.Commit;
      ConnectedOk := true;
   except
     on E:Exception do begin
       //only here because user is already logged in
       //message from database suffices
       if Transaction.InTransaction then
          Transaction.RollBack;
       ConnectedOk := false;
       ShowMessage(E.Message);
       Database.Connected := false;
       Close;

     end;
   end;


  end;
end;

Now all you need is a flag so you can remove the token
in ManageUsers table on clean exit

delete from ManageUsers where
  UName = Database.ConnectParams.UserName;

a better way would be to have a transaction dedicated
to this task and start the transaction OnLogin and
roll it back OnLogOut;

This way you could do something like
Update ManageUsers
  set UName = UName
  where UName = UName;

if row is already in update your transaction fails
otherwise you keep a lock on while user is connected

If your connection fails Firebird will rollback the
transaction shortly after the connection fails.
In addition you have a table where you can store user
preferences and states between instances

Mick



Send instant messages to your online friends http://au.messenger.yahoo.com


-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]



---------------------------------
Yahoo! Groups Links

   To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/

   To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



---------------------------------
Discover Yahoo!
Have fun online with music videos, cool games, IM & more. Check it out!

[Non-text portions of this message have been removed]



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]



----------------------------------------------------------------------------
----
Yahoo! Groups Links

  a.. To visit your group on the web, go to:
  http://groups.yahoo.com/group/delphi-en/

  b.. To unsubscribe from this group, send an email to:
  [EMAIL PROTECTED]

  c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.




[Non-text portions of this message have been removed]



-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED] 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/delphi-en/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to