作者在 2012-04-01 21:43:11 发布以下内容
关键技术
在命名空间添加using System.Web.Security引用。
FormsAuthentication类的HashPasswordForStoringInConfigFile方法
简单说一下它的语法:
public static string HashPasswordForStoringInConfigFile(string password,string passwordFormat)
password:要进行哈希运算的密码
passwordFormat:要使用的哈希算法。passwordformt是一个string,表示formsauthpasswordformat的每句值一直
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Security;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string sr = "MD5加密";
Response.Write("加密前的数据");
Response.Write(sr);
Response.Write("<br>");
Response.Write("加密后的数据");
Response.Cookies["data"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(sr, "MD5");
Response.Write(Response.Cookies["data"].Value);
}
}
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Security;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string sr = "MD5加密";
Response.Write("加密前的数据");
Response.Write(sr);
Response.Write("<br>");
Response.Write("加密后的数据");
Response.Cookies["data"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile(sr, "MD5");
Response.Write(Response.Cookies["data"].Value);
}
}