身份验证cookie [英] Authentication Cookie

查看:85
本文介绍了身份验证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:


  1. 使用一个标记

  2. 哈希时,它存储在数据库中的令牌。

  3. 请饼干的仅Http

  1. Use a token.
  2. Hash the token when it is stored in the database.
  3. 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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