身份验证cookie

编程入门 行业动态 更新时间:2024-10-11 03:24:04
本文介绍了身份验证cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在写一个数据库认证系统,这是在ASP.NET MVC wrriten我的Web应用程序。当有人授权,就应该救他的饼干用户名。它是安全的只使用了Htt presponse.Cookies`保存一个cookie,它的值是用户名?那不是伪造的?

I'm writing a database authentication system for my web application which is wrriten in ASP.NET MVC. When someone authorize, it should save his username in cookies. Is it safe to just use HttpResponse.Cookies` for saving a cookie that its value is username? Wouldn't it forgeable?

仅保存用户名...它是正确的和安全的方式?或者我应该保存整个用户对象(如果这实际上是可能的)?

Saving only the username... Is it the right and safe way? Or should I save the whole User object (if this actually possible)?

谢谢你,对不起我的英语。

Thank you and sorry for my English.

推荐答案

没有,节省了用户名是非常不安全的,因为它可以很容易伪造。这里是我的准则:

No, saving the username is very insecure, because it can be easily faked. Here are my guidelines:

  • 使用一个标记
  • 哈希时,它存储在数据库中的令牌。
  • 请饼干的仅Http
  • Use a token.
  • Hash the token when it is stored in the database.
  • Make the cookie HttpOnly.
  • 令牌可以通过CSPRNG生成,以确保自动登录cookie无法伪造。

    Tokens can be generated by a CSPRNG to ensure that the auto-login cookie can not be faked.

    在数据库prevents用户帐户,您的数据库泄露的情况下窃取散列令牌。 (请注意,在这一点上的标记是一个密码相当于。)

    Hashing the tokens in the database prevents user account stealing in the case that you database is compromised. (Remember, the token at this point is a password-equivalent.)

    仅HTTP的饼干prevent XSS攻击可能窃取cookie中。

    HTTP-Only cookies prevent XSS attacks that could potentially steal the cookie.

    更多推荐

    身份验证cookie

    本文发布于:2023-11-15 16:22:27,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1596045.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:身份验证   cookie

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!