コード例 #1
0
        public ActionResult Index(Customer _customer)
        {
            var _fCustomer = db.Customer.Where(p => p.Statedelete == false && (p.UserName == _customer.UserName || p.Email == _customer.UserName)).FirstOrDefault();

            if (_fCustomer != null)
            {
                string encriptpass = CreatHash.HashPass(_customer.Password);

                string hashid = CreatHash.Encrypt(_fCustomer.Id.ToString());

                if (_fCustomer.Password == encriptpass)
                {
                    HttpCookie cookie = new HttpCookie("customerId");

                    cookie.Value   = hashid;
                    cookie.Expires = DateTime.Now.AddDays(1);
                    Response.Cookies.Add(cookie);
                    return(RedirectToAction("Index", "CustumerArea"));
                }
                else
                {
                    ViewBag.WrongIdentity = "1";
                    return(View());
                }
            }
            else
            {
                ViewBag.WrongIdentity = "1";
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Index(Users _user)
        {
            Users admin = null;

            try
            {
                admin = db.Users.Where(p => p.UserName == _user.UserName).FirstOrDefault();
                if (admin != null)
                {
                    var pass = CreatHash.HashPass(_user.Password);
                    if (admin.Password == pass)
                    {
                        string Id = CreatHash.Encrypt(admin.Id.ToString());



                        HttpCookie UserIdcookie = new HttpCookie("UserId");
                        UserIdcookie.Value   = Id;
                        UserIdcookie.Expires = DateTime.Now.AddMinutes(30);
                        Response.Cookies.Add(UserIdcookie);

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ViewBag.WrongPassword = "******";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.WrongPassword = "******";

                    return(View());
                }
            }
            catch (Exception ee)
            {
                ViewBag.WrongPassword = "******";

                return(View());
            }
        }