使简单会员 cookie 更安全

发布于 2024-11-15 10:13:55 字数 556 浏览 2 评论 0原文

ASP.net Web Pages 堆栈带有简单成员资格,其中最好的解释是 Matthew Osborn 的 < a href="http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx" rel="nofollow noreferrer">使用 SimpleMembership。 SimpleMembership 是一个轻量级的用户/登录/会员系统,它允许使用 cookie 来实现“记住我”登录目的。我想通过强制 cookie 为 httpOnly 并成为 安全(仅 https)cookie 来提高 cookie 的安全性。我该怎么做?

更新:@Darin Dimitrov 指出 httpOnly 仅是会话,这不是我想要的。

ASP.net Web Pages stack comes with Simple Membership, of which the best explanation is Matthew Osborn's Using SimpleMembership. SimpleMembership is a lightweight user/login/membership system which allows a cookie to be used for "remember me" login purposes. I would like to improve the the security of the cookie by forcing the cookie to be httpOnly and be a secure (https only) cookie. How can I do this?

Update: @Darin Dimitrov pointed out that httpOnly is session only which is not what I want.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-11-22 10:13:55

如果您不使用持久性 Cookie,则意味着该 Cookie 不再存储在客户端计算机上,这违背了记住我功能的全部目的。 HttpOnly cookie 存储在浏览器的内存中,但仅限于给定的会话。为了提高安全性,请确保使用 secure 标志,指示此 cookie 将仅通过加密连接传输。

If you don't use a persistent cookie that would mean that the cookie is no longer stored on the client computer which kind of defeats the whole purpose of the remember me functionality. HttpOnly cookies are stored in the memory of the browser but only for the given session. In order to improve security make sure that the cookie is set with the secure flag which indicates that this cookie will be transmitted only over an encrypted connection.

对你而言 2024-11-22 10:13:55

如果这适用于您,我建议您查看源代码并了解它是如何完成的:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/9c98c6e9a150#src%2fWebMatrix.WebData%2fWebSecurity.cs

现在我已经检查了自己......:)这个是它们现在的样子:

    public static bool Login(string userName, string password, bool persistCookie = false)
    {
        VerifyProvider();
        bool success = Membership.ValidateUser(userName, password);
        if (success)
        {
            FormsAuthentication.SetAuthCookie(userName, persistCookie);
        }
        return success;
    }

    public static void Logout()
    {
        VerifyProvider();
        FormsAuthentication.SignOut();
    }

其中 Membership 提供与 System.Web.Security.Membersip 大致相同的 API —— 实际上与启动时的 WebMatrix.WebData.SimpleMembershipProvider。

基本上,如果您想要自定义身份验证 cookie 机制,您必须实现自己的登录和登录。注销逻辑。网络上有大量这方面的示例。

我希望这会有所帮助。
祝你好运! :)

If that applies to you, I suggest to have a look at the source code and see how it's done:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/9c98c6e9a150#src%2fWebMatrix.WebData%2fWebSecurity.cs

Now that I've checked myself... :) this is how they look as of now:

    public static bool Login(string userName, string password, bool persistCookie = false)
    {
        VerifyProvider();
        bool success = Membership.ValidateUser(userName, password);
        if (success)
        {
            FormsAuthentication.SetAuthCookie(userName, persistCookie);
        }
        return success;
    }

    public static void Logout()
    {
        VerifyProvider();
        FormsAuthentication.SignOut();
    }

Where Membership provides about the same API as the System.Web.Security.Membersip -- which is actually swapped with WebMatrix.WebData.SimpleMembershipProvider at startup.

Basically if you want a custom auth cookie mechanism you've got to implement your own login & logout logic. The web has plenty of samples in that direction.

I hope this helps a bit.
Good luck! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文