The easiest way to restrict this is a two part system. Part 1 restricts the terminal to one instance of the program. If the program is already running, do not allow another session to start.
Part 2 checks to see of the user is in the ManageUsers table. If an entry exists check the terminal value, if it is not the current terminal exit the program. -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Vahan Yoghoudjian Sent: Wednesday, June 08, 2005 10:24 AM To: [email protected] Subject: RE: [delphi-en] Re: Restrict only 1 terminal login for 1 user John... what if the database runs 24/24? I think in SQL server there's a table that shows you who has logged in, I'm not sure about Firebird/Interbase tho... Let's go back to Oracle, even if there's a table storing the login information what happens again when there's a power failure... how does Oracle solve this problem... Does it ping the terminal from time to time to see if there's still a connection? does it force the user to disconnect after some idle delay? what if this delay is not expired yet and the user tries to reconnect from the same machine or from a different machine? Vahan -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of John Dorlon Sent: Wednesday, June 08, 2005 3:17 PM To: [email protected] Subject: RE: [delphi-en] Re: Restrict only 1 terminal login for 1 user I have an idea, I don't know if it works in interbase or firebird, but it works in Oracle. In Oracle, there is a data dictionary (ie, system-owned) view that you can query to see who is logged in. So if you have such a thing in your database, query that in your login trigger. Another idea (going back to adding login data to a table in a login trigger) - at some point you asked "what happens if there is a power failure - the data could get out of sync with the users?" To remedy this (if it's possible) you could make a trigger run at database startup which would delete all the rows from the table. -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] Behalf Of Vahan Yoghoudjian Sent: Wednesday, June 08, 2005 2:02 AM To: [email protected] Subject: RE: [delphi-en] Re: Restrict only 1 terminal login for 1 user 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 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 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 ----------------------------------------------------- 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/

