昨夜飘风
昨 夜, 风, 飘 过; 枯 树, 叶, 飞 落。

     你的主页或者你管理的网站有各种密码需要保护,把密码直接放在数据库或者文件中存在不少安全隐患,所以密码加密后存储是最常见的做法。在ASP.NET中实现加密非常容易。.NET SDK中提供了CookieAuthentication类,其中的HashPasswordForStoringInConfigFile方法可直接使用MD5和SHA1算法。例子如下:

 

public void SavePassWord_Click (object sender, System.EventArgs e)
 {
  MD5.Text 
= CookieAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text,"MD5");
  
//SHA1 use CookieAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text,"SHA1");
 }

 

注意:类CookieAuthentication的namespace是System.Web.Security

posted on 2008-11-04 10:07  昨夜飘风  阅读(649)  评论(0编辑  收藏  举报