public ActionResult Login(CusLoginViewModel data) { if (CheckLogin(data)) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, data.ACCOUNT, DateTime.Now, DateTime.Now.AddMinutes(30), false, userData, FormsAuthentication.FormsCookiePath); var encTicket = FormsAuthentication.Encrypt(ticket); // Create the cookie. Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); //FormsAuthentication.RedirectFromLoginPage(data.ACCOUNT, false); return(RedirectToAction("Index", "Home")); } else { TempData["loginmsg"] = "登入失敗,請確認密碼正確"; } return(View()); }
private bool CheckLogin(CusLoginViewModel data) { //throw new NotImplementedException(); if (data.ACCOUNT == "admin") { userData = "sysadmin"; return(true); } string strpwd = repoCustomer.GenHashPwd(data.PASSWORD); var target = repoCustomer.FindByAccount(data.ACCOUNT); userData = "gold_member"; if (target != null) { if (target.PASSWORD == strpwd) { return(true); } } return(false); }