我正在写一个数据库认证系统,这是在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:
令牌可以通过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
发布评论