Exemplo n.º 1
0
        public void TestRevEnc()
        {
            //可逆加密
            //des
            string desEncode = DEncryptUtils.DESEncrypt(txt, key);

            Console.WriteLine("des加密值:" + desEncode);
            Assert.AreEqual(txt, DEncryptUtils.DESDecrypt(desEncode, key));

            //aes
            string aesEncode = DEncryptUtils.AESEncrypt(txt);

            Console.WriteLine("aes加密值:" + aesEncode);
            Assert.AreEqual(txt, DEncryptUtils.AESDecrypt(aesEncode));

            //base64
            string base64Encode = DEncryptUtils.Base64Encrypt(txt);

            Console.WriteLine("base64加密值:" + aesEncode);
            Assert.AreEqual(txt, DEncryptUtils.Base64Decrypt(base64Encode));

            //xor
            string xor = DEncryptUtils.GetXORCode(txt, key);

            Console.WriteLine("xor加密值:" + xor);
            Assert.AreEqual(txt, DEncryptUtils.GetXORCode(xor, key));
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            string email    = context.Request.Form["user[email]"];
            string pwd      = context.Request.Form["user[pwd]"];
            string remember = context.Request.Form["user[remember]"];

            int       i = -1;
            DataTable dt;

            if (email.IndexOf("@", StringComparison.Ordinal) > -1)
            {
                dt = MemberBll.Instance.GetList("Email='" + email + "' AND Password='******'").Tables[0];
            }
            else
            {
                dt = MemberBll.Instance.GetList("User_name='" + email + "' AND Password='******'").Tables[0];
            }

            if (dt.Rows.Count > 0)
            {
                CookieHelper cookieHelper = null;
                if (remember == "1") //下次自动登录,设置cookie为一个月
                {
                    cookieHelper = new CookieHelper("52cos", DateTime.Now.AddMonths(1));
                }
                else
                {
                    cookieHelper = new CookieHelper("52cos");                                                  //默认关闭浏览器,失效
                }
                cookieHelper.SetCookie("user_id", DEncryptUtils.DESEncrypt(dt.Rows[0]["User_id"].ToString())); //将user_id添加到cookie
                cookieHelper.SetCookie("pwd", dt.Rows[0]["Password"].ToString());                              //将Password添加到cookie
                i = 1;
            }
            else
            {
                i = 0;
            }
            context.Response.ContentType = "text/plain";
            context.Response.Charset     = "utf-8";
            context.Response.Write(i);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 数据库字符串加密
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     textBox2.Text = DEncryptUtils.DESEncrypt(textBox1.Text);
 }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            string    nickname = context.Request.Form["user[nickname]"];
            string    email    = context.Request.Form["user[email]"];
            string    pwd      = context.Request.Form["user[pwd]"];
            string    s        = "{\"status\":\"error\"}";
            bool      b        = false;
            DataTable dt       = MemberBll.Instance.GetList("Email='" + email + "'").Tables[0];

            if (dt.Rows.Count > 0)
            {
                s = "{\"status\":\"exist\"}";
                return;
            }

            MemberEntity memberEntity = new MemberEntity();

            memberEntity.User_name = "";
            memberEntity.Email     = email;
            memberEntity.Password  = DEncryptUtils.Encrypt3DES(pwd);
            memberEntity.Real_name = "";
            memberEntity.nickname  = nickname;
            memberEntity.Gender    = memberEntity.Birthday = memberEntity.Phone_tel = memberEntity.Phone_mob = memberEntity.Im_qq = memberEntity.Im_msn
                                                                                                                                        = memberEntity.In_skype = memberEntity.Im_yahoo = memberEntity.Im_aliww = memberEntity.Outer_id
                                                                                                                                                                                                                      = memberEntity.Feed_config = "";
            memberEntity.Portrait   = "/Upload/Portrait/1.jpg";
            memberEntity.Reg_time   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            memberEntity.Last_login = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            memberEntity.Last_ip    = new BasePage().ClientIP;
            memberEntity.Logins     = 0;
            memberEntity.Ugrade     = 1;
            memberEntity.Status     = 1;
            memberEntity.reward     = 0;
            memberEntity.CNbi       = 0;
            memberEntity.integral   = 0;
            memberEntity.ardent     = 0;
            memberEntity.Growth     = 0;
            memberEntity.code       = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Guid.NewGuid().ToString(), "MD5");
            memberEntity.Activation = "0";
            memberEntity.Describe   = "";
            memberEntity.Shenjia    = 0;
            memberEntity.Bean       = "0";

            StringBuilder mailBody = new StringBuilder();

            mailBody.AppendFormat(EmailConfig.Instance._EmailBody, memberEntity.nickname, HttpContext.Current.Request.Url.Host, memberEntity.code);

            //发送注册邮件
            b = MemberApi.SendRegisterMail(memberEntity.nickname, memberEntity.code, memberEntity.Email);
            if (b)
            {
                b = MemberBll.Instance.Add(memberEntity) > 0;
                if (b)
                {
                    CookieHelper cookieHelper = new CookieHelper("52cos", DateTime.Now.AddMonths(1));
                    dt = MemberBll.Instance.GetList("Email='" + memberEntity.Email + "' and Password='******'").Tables[0];
                    cookieHelper.SetCookie("user_id", DEncryptUtils.DESEncrypt(dt.Rows[0]["User_id"].ToString())); //将user_id添加到cookie
                    cookieHelper.SetCookie("pwd", memberEntity.Password);                                          //将Password添加到cookie
                    s = "{\"status\":\"success\"}";
                }
            }


            context.Response.ContentType = "text/plain";
            context.Response.Write(s);
        }