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:
http://docs.yahoo.com/info/terms/