1 //命名空间
2 using System;
3 using System.Collections;
4 using System.Configuration;
5 using System.Data;
6 using System.Linq;
7 using System.Web;
8 using System.Web.Security;
9 using System.Web.UI;
10 using System.Web.UI.HtmlControls;
11 using System.Web.UI.WebControls;
12 using System.Web.UI.WebControls.WebParts;
13 using System.Xml.Linq;
14 using System.IO;
15 using System.Text;
16 using System.Security.Cryptography;
17 using Discuz.Common;//引用论坛的Discuz.Common.dll
18 using System.Text.RegularExpressions;
2 using System;
3 using System.Collections;
4 using System.Configuration;
5 using System.Data;
6 using System.Linq;
7 using System.Web;
8 using System.Web.Security;
9 using System.Web.UI;
10 using System.Web.UI.HtmlControls;
11 using System.Web.UI.WebControls;
12 using System.Web.UI.WebControls.WebParts;
13 using System.Xml.Linq;
14 using System.IO;
15 using System.Text;
16 using System.Security.Cryptography;
17 using Discuz.Common;//引用论坛的Discuz.Common.dll
18 using System.Text.RegularExpressions;
1 string encryptString = "e10adc3949ba59abbe56e057f20f883e";//从论坛中取出用户所属md5加密后的密码
2 string encryptKey = "RV8JX664X8";//论坛文件夹Discuz.Web\config\general.config中找到<Passwordkey>节点获取key
3 encryptKey = Utils.GetSubString(encryptKey, 8, "");
4 encryptKey = encryptKey.PadRight(8, ' ');
5 byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
6 byte[] rgbIV = Keys;
7 byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
8 DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
9 MemoryStream mStream = new MemoryStream();
10 CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
11 cStream.Write(inputByteArray, 0, inputByteArray.Length);
12 cStream.FlushFinalBlock();
13 HttpCookie co = new HttpCookie("dnt");//Cookie名字
14 co["userid"] = "1";//登陆者编号ID
15 co["password"] = Utils.UrlEncode(Convert.ToBase64String(mStream.ToArray())).ToString();
16 //第二次经过处理后的密码存入cookie中
17 HttpContext.Current.Response.Cookies.Add(co);//cookie保存,刷新论坛首页 用户已经处于登陆状态了
3 encryptKey = Utils.GetSubString(encryptKey, 8, "");
4 encryptKey = encryptKey.PadRight(8, ' ');
5 byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
6 byte[] rgbIV = Keys;
7 byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
8 DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
9 MemoryStream mStream = new MemoryStream();
10 CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
11 cStream.Write(inputByteArray, 0, inputByteArray.Length);
12 cStream.FlushFinalBlock();
13 HttpCookie co = new HttpCookie("dnt");//Cookie名字
14 co["userid"] = "1";//登陆者编号ID
15 co["password"] = Utils.UrlEncode(Convert.ToBase64String(mStream.ToArray())).ToString();
16 //第二次经过处理后的密码存入cookie中
17 HttpContext.Current.Response.Cookies.Add(co);//cookie保存,刷新论坛首页 用户已经处于登陆状态了