单点登录(多台机只能一个用户登录,把另一用户踢下)思路

1、写一个保存SessionInfo的类,用户ID,SessionID等。


2、写一静态Hashtable保存用户Session map(保存1的SessionInfo类,key保存的是用户ID)


3、在写Session的方法里,先通过用户ID(key)从Hashtable里获取SessionInfo类(1的SessionInfo类),如果存在此SessionInfo类,则移除Session;如果不存在则封装SessionInfo对象,把Session的ID赋值给SessionInfo对象的SessionID,然后以SessionInfo为Session的值保存Session,并以用户ID为键,SessionInfo为值,保存在Hashtable。


4、在读取Session验证的BasePage页中,获取当前Session的ID,再获取Hashtable中SessionInfo对象的SessionID,如果Hashtable中SessionInfo对象为空则跳到出错或登录页,如果不为空,则判断两个SessionID是否相等,如果不相等,则跳到出错页或登录页,如果相等表示还是当前用户。


5、在退出时也重复4的操作,只是如果两个SessionID相等,则移除Hashtable中的SessionInfo对象。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在 Windows 操作系统下,使用 C++ 实现连接局域网中的一台主并创建共享文件夹的代码: ```c++ #include <iostream> #include <windows.h> #include <lm.h> #pragma comment(lib, "netapi32.lib") int main() { // 填写共享文件夹的名称和路径 std::wstring shareName = L"MySharedFolder"; std::wstring sharePath = L"C:\\MyFolder"; // 填写远程主名和用户名、密码(如果需要认证) std::wstring remoteHost = L"192.168.1.100"; std::wstring remoteUser = L"Administrator"; std::wstring remotePass = L"password"; // 连接远程主 NETRESOURCE netResource; netResource.dwType = RESOURCETYPE_DISK; netResource.lpLocalName = NULL; netResource.lpRemoteName = const_cast<wchar_t*>(remoteHost.c_str()); netResource.lpProvider = NULL; DWORD res = WNetAddConnection2(&netResource, remotePass.c_str(), remoteUser.c_str(), 0); if (res != NO_ERROR) { std::wcerr << L"Failed to connect to remote host: " << res << std::endl; return 1; } // 创建共享文件夹 SHARE_INFO_2 shareInfo; shareInfo.shi2_netname = const_cast<wchar_t*>(shareName.c_str()); shareInfo.shi2_type = STYPE_DISKTREE; shareInfo.shi2_remark = NULL; shareInfo.shi2_permissions = ACCESS_ALL; shareInfo.shi2_max_uses = -1; shareInfo.shi2_current_uses = 0; shareInfo.shi2_path = const_cast<wchar_t*>(sharePath.c_str()); shareInfo.shi2_passwd = NULL; res = NetShareAdd(NULL, 2, reinterpret_cast<LPBYTE>(&shareInfo), NULL); if (res != NERR_Success) { std::wcerr << L"Failed to create share: " << res << std::endl; } // 断开连接 WNetCancelConnection2(remoteHost.c_str(), 0, TRUE); return 0; } ``` 这段代码使用了 Windows API 中的 WNetAddConnection2 和 NetShareAdd 函数,其中 WNetAddConnection2 用于连接远程主,NetShareAdd 用于创建共享文件夹。注意在代码中填写正确的远程主名、用户名和密码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值