Session 数据库中的模拟会话:如何确定过时的值?
我有一个会话系统,其中记录的用户存储在会话(内存)中。问题是应用程序无法扩展(克隆服务器)。它只能放大(改进服务器) 现在:我的新用户系统由数据库中的用户表和cookies表组成Session 数据库中的模拟会话:如何确定过时的值?,session,cookies,login-control,Session,Cookies,Login Control,我有一个会话系统,其中记录的用户存储在会话(内存)中。问题是应用程序无法扩展(克隆服务器)。它只能放大(改进服务器) 现在:我的新用户系统由数据库中的用户表和cookies表组成 Users(username, hashedpassword) Cookies(username, secretcookie, expiration) 登录表单包括三个字段:“用户名”、“密码”和“保持连接”复选框 以伪代码形式处理表单的代码如下所示: if username and password are
Users(username, hashedpassword)
Cookies(username, secretcookie, expiration)
登录表单包括三个字段:“用户名”、“密码”和“保持连接”复选框
以伪代码形式处理表单的代码如下所示:
if username and password are correct
{
secretValue = new GUID();
create a cookie in the client, containing the secretValue.
if (stayConnected)
{
-make the cookie expire in 30 days
-add to table "Cookies" this registry: (username, secretValue, now+30days)
}
else
{
-dont set an expiration date (ie: cookie expires when browser closes)
-add to table "Cookies" this registry: (username, secretValue, null)
}
}
这与使用会话几乎相同,但我现在使用的是数据库而不是内存。我知道它很容易受到会话HIJAK的攻击,但我以前的系统也很脆弱 问题是:
我的“Cookies”表包含许多过时的值(由于客户端关闭了浏览器,客户端中的Cookies已经过期),确定要删除哪些cookie的好策略是什么?您需要在后端设置一个脚本,每隔一段时间就删除一次过期日期小于现在的cookie,这些cookie很容易删除,但是没有过期日期的cookie呢?浏览器关闭时应该过期的(即:没有明确的日期)。我如何管理这些?