using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Web; namespace JumboTCMS.WebFile.PeiXue.Tools { /// /// Login 的摘要说明 /// public class Login : IHttpHandler { private static byte[] Keys = { 0x13, 0x35, 0x56, 0x79, 0x91, 0xAC, 0xCB, 0xBF }; public string Conn = System.Configuration.ConfigurationManager.ConnectionStrings["PexueConnection"].ToString(); public void ProcessRequest(HttpContext context) { string UserName = context.Request.Params["UserName"]; string Userpass = context.Request.Params["Userpass"]; context.Response.ContentType = "text/plain"; try { System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(Conn); connection.Open(); System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(); command.Connection = connection; command.CommandText = "select * from [User] where UserName='" + UserName + "'"; System.Data.SqlClient.SqlDataAdapter reader = new System.Data.SqlClient.SqlDataAdapter(command.CommandText, connection); System.Data.DataSet ds = new System.Data.DataSet(); reader.Fill(ds); connection.Close(); connection.Dispose(); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { var pass = ds.Tables[0].Rows[0]["UserPassword"].ToString(); if (pass.Equals(EncryptDES(Userpass))) { if (ds.Tables[0].Rows[0]["Islock"].ToString() == "False") { HttpCookie cookie = new HttpCookie("user"); cookie.Values.Add("UserName", ds.Tables[0].Rows[0]["UserName"].ToString()); cookie.Values.Add("UserId", ds.Tables[0].Rows[0]["UserId"].ToString()); context.Response.Cookies.Add(cookie); context.Response.Write("yes"); } else { context.Response.Write("jihuo"); } } else { context.Response.Write("perror"); } } else { context.Response.Write("uerror"); } } catch (Exception ex) { } } public bool IsReusable { get { return false; } } /// /// DES加密字符串 /// /// 待加密的字符串 /// 加密密钥,要求为8位 /// 加密成功返回加密后的字符串,失败返回源串 public string EncryptDES(string encryptString) { string encryptKey = "ZhongruiOnline"; try { byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8)); byte[] rgbIV = Keys; byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString); DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider(); System.IO.MemoryStream mStream = new System.IO.MemoryStream(); CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write); cStream.Write(inputByteArray, 0, inputByteArray.Length); cStream.FlushFinalBlock(); // var s=Convert.ToBase64String(mStream.ToArray()); return Convert.ToBase64String(mStream.ToArray()); } catch { return encryptString; } } } }