Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restrict number of users

Status
Not open for further replies.

codetyko

Programmer
May 26, 2001
73
MY
Is there a way to programmatically (in fpw26) control the number of users currently assessing the data on the server? What I want to do is to package the software according to the number of users. 1-5 users will cost a certain amount and any additional user will cost extra. Therefore even if the user installs more than the allocated copies, the system will only allow the stipulated number of users at any one time. Thanks in advance!
 
Codetyko,
There are several ways, all of which will require some code on your part, and there are a few caveat's to them. One of the better approaches I've found is to do the following:

Create a .DBF file called CONTROL.DBF It should have the following structure:

Fieldname Type
USERID C10
LOGINDATE D

One of the main problems with this type of control is that, if the app crashes for some reason, The value won't get reset... for that reason, I track date, and time, and then make an assumption... it's fairly reliable. I also assume here you have some type of User-ID implemented in your code, and that a user has to log on. If you do not, let me know, and I will e-mail you my security routines. I will assume that you capture the Users ID in some type of memvar, for this example, I'll call it M.USERID. The code you will add immediatly after your logon is:

IF NOT USED('CONTROL')
SELECT 0
USE CONTROL
ELSE
SELECT CONTROL
ENDIF
*
* The code below is to reset the file, basically daily.
* This will clear the file, in the even that someone
* exited the application "Ungracefully". Usually, due
* to the application crashing. Since the number of
* records is basically what we are monitoring, ZAPPING
* the table, basically the first time someone logs in
* on a daily basis, resets it's total count. It's not
* fool prof, but it works fairly well. A good hacker
* could fool it...
SELECT CONTROL
GO BOTT
IF DATE() # CONTROL.LOGINDATE
SELECT CONTROL
USE CONTROL EXCLUSIVE
ZAP
ENDIF
*
IF RECCOUNT('CONTROL') >= 5
WAIT 'Maximum Number Of Users Already Logged In. Please Try Again Later.' WINDOW TIMEOUT 5
CLEAR READ ALL
QUIT
ELSE
SELECT CONTROL
APPEND BLANK
REPLACE USERID WITH M.USERID;
LOGINDATE WITH DATE()
ENDIF
*

Note that, as an alternative to the code in the ELSE clause above, you can do this instead if you also want to ensure that no single user is logged in more than once. (Note that I use a LOCATE here for simplicity, since this file will NEVER be very large, and would run fast on even the SLOWEST of machines... I don't normally advocate the use of LOCATE, but in this case it is very effective.)

ELSE
SELECT CONTROL
LOCATE ALLTRIM(CONTROL.USERID) = (M.USERID)
IF FOUND()
WAIT 'User already logged on. Can not log-on more than once.' WINDOW TIMEOUT 5
CLEAR READ ALL
QUIT
ELSE
SELECT CONTROL
APPEND BLANK
REPLACE USERID WITH M.USERID;
LOGINDATE WITH DATE()
ENDIF


Now, the only other thing you will need to do, is at the point in time that your user exits the application, (Like, on a Quit or Exit, whatever you use...) add this code:

IF NOT USED('CONTROL')
SELECT 0
USE CONTROL EXCL
ELSE
SELECT CONTROL
ENDIF
*
LOCATE FOR M.USERID = CONTROL.USERID
IF FOUND() && Don't know why you wouldn't, but it's
&& a good code habit...
DELETE
ENDIF
*
PACK
.
.
.
<EXIT APPLICATION CODE GOES HERE...>

Hope this helps... it's a little klugy, but with some work, you could easily improve upon it.
Please let me know if this helps, or if you need additional details, or explanation.
Cheers,
-Scott
 
Dear Scott,
Thank you very much for your recommendation. By the way, could you pass on your security features to me (the user ID routine) in order for me to implement the code? I still consider myself raw in experience compared to you guys. Thanks in advance.
 
You might check out the threads on this topic on the VFP forum -- Ramani has a pretty slick method and does some automatic releasing if you have a crash.

 
Hi

1. Create one &quot;MyUsers&quot; Table in the network place.

2. Have in that file exactly as many records as the number of users.

3. As and when the users log in to the application, the first thing to do is to LOCK one available unlocked record in this user file. This means, MyUser file will remain open with one record locked at startup. The DBF can be opened in say 50 or so slot with an alais, and remember to leave this file open always. So whenever individual programs open tables and closes, remember to close all except this user file. Only Quit from the software shall close this file. What we achieve by this is that the users one record remains locked till he logs out.

4. Forget about this file.. till the user logs out of application.

5. If a user cannot get a free record.. it means the limit is reached.. and you can put up a message and log out the user.

The thing is that when a system crashes, the record lock automatically gets removed, and the record becomes available. No clean up is required. A similar suggestion has been provided by me else where in this forum with more details.

Ramani ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top