62,074
社区成员
发帖
与我相关
我的任务
分享
//命名空间
using System;
using System.Collections;
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.IO;
using System.Text;
using System.Security.Cryptography;
using Discuz.Common;//引用论坛的Discuz.Common.dll
using System.Text.RegularExpressions;
string encryptString = "e10adc3949ba59abbe56e057f20f883e";//从论坛中取出用户所属md5加密后的密码
string encryptKey = "RV8JX664X8";//论坛文件夹Discuz.Web\config\general.config中找到<Passwordkey>节点获取key
encryptKey = Utils.GetSubString(encryptKey, 8, "");
encryptKey = encryptKey.PadRight(8, ' ');
byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
byte[] rgbIV = Keys;
byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
HttpCookie co = new HttpCookie("dnt");//Cookie名字
co["userid"] = "1";//登陆者编号ID
co["password"] = Utils.UrlEncode(Convert.ToBase64String(mStream.ToArray())).ToString();
//第二次经过处理后的密码存入cookie中
HttpContext.Current.Response.Cookies.Add(co);//cookie保存,刷新论坛首页 用户已经处于登陆状态了
private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }