欢迎来到.net学习网

欢迎联系站长一起更新本网站!QQ:879621940

您当前所在位置:首页 » ASP.Net » 正文

热门阅读

探索ASP.NET Forms验证的相关安全性问题

创建时间:2011年06月16日 22:54  阅读次数:(5227)
分享到:

ASP.NET Forms验证主要是为了防止Forms被破解危害网站的安全,今天我们将从简单的Forms开始讲述,最后讲解危机将带来什么后果。

ASP.NET提供了内置的登录验证,最为常用的就是Forms验证。讲解如何配置的文章非常多,这里就不再讲如何配置使用这个验证的方式了。下面讲讲其在安全性上存在的一些被忽视的问题。其实它本身没有问题,而使用的方式上会附带出来一些问题。

本文将分三部分讲实际应用中将会遇到的安全性问题,并且加以研究,并尝试提出解决方案。

一、简单的Forms被破解危机

二、垂直划分站点的Forms被破解危机

三、危机将带来什么后果

一、简单的Forms被破解危机

最简单的一个ASP.NET Forms验证,在web.config下配置节点:

  1. <authentication mode="Forms"> 
  2.     <forms name=".MyCookies"></forms> 
  3. </authentication> 

编写一个帮助类:

  1. CookieHelper类  
  2.     public static class CookieHelper {  
  3.         public static string Encrypt(string name, string value) {  
  4.             FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, name, DateTime.Now, DateTime.Now.AddDays(1), true, value, "/");  
  5.             string authTicket = FormsAuthentication.Encrypt(ticket);  
  6.             return authTicket;  
  7.         }  
  8.  
  9.         public static void Set(string name, string value) {  
  10.             HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, Encrypt(name, value));  
  11.             cookie.Expires = DateTime.Now.AddDays(1);  
  12.             if (HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName] == null)  
  13.                 HttpContext.Current.Response.Cookies.Add(cookie);  
  14.             else 
  15.                 HttpContext.Current.Response.Cookies.Set(cookie);  
  16.         }  
  17.  
  18.         public static string Get() {  
  19.             if (HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName] == null)  
  20.                 return null;  
  21.             else {  
  22.                 return HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value;  
  23.             }  
  24.         }  
  25.  
  26. 来源:
    说明:所有来源为 .net学习网的文章均为原创,如有转载,请在转载处标注本页地址,谢谢!
    【编辑:Wyf

    打赏

    取消

    感谢您的支持,我会做的更好!

    扫码支持
    扫码打赏,您说多少就多少

    打开支付宝扫一扫,即可进行扫码打赏哦

最新评论

共有评论0条
  • 暂无任何评论,请留下您对本文章的看法,共同参入讨论!
发表评论:
留言人:
内  容:
请输入问题 99+56=? 的结果(结果是:155)
结  果: