如何只允许有限数量的用户登录? [英] How to allow only limited no of users to login?

查看:75
本文介绍了如何只允许有限数量的用户登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用户端有一个Windows应用程序,在管理员端有一个Web服务,它们连接在LAN中...当用户运行Windows应用程序时,会有一个登录表单,并且当用户登录Web服务时进行调用,并将行(包含用户的详细信息)动态添加到位于管理端的数据库表中.现在我希望只有指定的用户数才能登录,即如果admin给3个用户,那么只有3个用户应能登录,并且如果第4个用户尝试登录,它应该给出一条错误消息``否''.的用户已超过.我试图使用for循环来做到这一点:

I have one windows application at the user side and a web service at the admin side which are connected in the LAN...when the user runs the windows application there is a login form and when the user logs in a web service call is made and a row (containing details of the user) is dynamically added into the table of the database present at the admin side. Now I want that only the specified no of users should be able to login i.e. if admin gives 3 users then only 3 users should be able to login and if the 4th user tries to login it should give an error message that no. of users have exceeded. I tried to do this using for loop as:

for(count=0 ; count<noofusers mode="hold" />{
      //code for inserting the row dynamically into database
}



但同时将3行添加到数据库中

我希望当1个用户登录时应添加1行,当另一个用户登录时应增加NOOfUsers并应添加第二行,依此类推...最终当第4个用户登录时,他不应被允许...

有人可以帮我解决这个问题吗?



but here simultaneously 3 rows are added into the database

I want that when 1 user logins 1 row should be added, when another user logins the NOOfUsers should be incremented and 2nd row should be added and so on...finally when 4th user logins he should not be allowed to...

Can anyone please help me with this issue??

推荐答案

正如亨利所说,这没有任何意义.
但是,我认为这里有足够的信息可以说明您的问题是什么:
当需要if语句时,正在使用for循环.

如果设置一个for循环,它将多次执行相同的代码:这不是您的描述所说的.

当用户要登录时,请检查用户数".如果超过或等于最大值,则拒绝登录.否则,请增加用户数量并登录.
As Henry says, that doesn''t make a lot of sense.
However, I think there is enough there to tell what your problem is:
You are using a for loop, when you want an if statement.

If you set up a for loop, it will do the same code several times: that is not what your description says.

When a user wants to log in, check the "number of users". If this exceeds or equals the maximum, then refuse the login. Otherwise, increase the number of users, and log them in.
if (count >= noofusers)
   {
   // Refuse login
   ...
   }
else
   {
   count++;
   ...
   }



请注意,您将需要一些处理注销和死"用户的方法:例如,如果PC在没有注销的情况下重新启动,则需要终止用户登录并以某种方式减少计数.



Note that you will need something to cope with logout, and with "dead" users: for example if the PC gets re-booted without a log out you need to kill the user login and reduce the count somehow.


这篇关于如何只允许有限数量的用户登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆