public ActionResult UpdateMember() { var service = new CustomerService(); var passwordSaltService = new PasswordSaltService(); var cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie == null) { return(RedirectToAction("Login", "Login")); } var ticket = FormsAuthentication.Decrypt(cookie.Value); var customer = service.FindByCustomerAccount(ticket.Name); ViewBag.User = customer.Account; if (customer.Birthday != null) { ViewBag.birthday = DateTime.Parse(customer.Birthday.ToString()).ToShortDateString(); } var model = new UpdateMemberModel() { CustomerName = customer.CustomerName, Email = customer.Email, Phone = customer.Phone, Birthday = customer.Birthday }; return(View(model)); }
public void PasswordsCheckTest() { PasswordSaltService passwordSaltService = new PasswordSaltService(); var customer = service.FindByCustomerId(1); var result = passwordSaltService.PasswordsCheck(customer, "0312958"); Assert.IsTrue(result == true); }
public ActionResult Login(loginModel model) { var service = new CustomerService(); var passwordSaltService = new PasswordSaltService(); var customer_list = service.GetAll().ToList(); if (customer_list.Any((x) => x.Account == model.User) == false) { return(RedirectToAction("Login")); } ; if (model.Password == "******") { return(RedirectToAction("Login")); } if (passwordSaltService.PasswordsCheck(service.FindByCustomerAccount(model.User), model.Password)) { FormsAuthentication.SignOut(); var cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie != null) { cookie.Expires = DateTime.Now; Response.Cookies.Add(cookie); } FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, model.User, DateTime.Now, DateTime.Now.AddMinutes(30), false, "abcdefg"); var ticketData = FormsAuthentication.Encrypt(ticket); cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketData); cookie.Expires = ticket.Expiration; //設定Cookie到期日與憑證同時 Response.Cookies.Add(cookie); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("loginModel", "Error"); return(RedirectToAction("Login", "Login")); } }
public ActionResult UpdatePassword(UpdatePasswordModel model) { var service = new CustomerService(); var passwordSaltService = new PasswordSaltService(); var cookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie == null) { return(RedirectToAction("Login", "Login")); } var ticket = FormsAuthentication.Decrypt(cookie.Value); var customer = service.FindByCustomerAccount(ticket.Name); try { if (!passwordSaltService.Validate(model.Password)) { ViewBag.Msg = "密碼不符合規範"; return(View()); } if (model.Password != model.Password2) { ViewBag.Msg = "密碼與確認密碼不符"; return(View()); } var model2 = new Customer() { CustomerID = customer.CustomerID, Password = model.Password }; service.UpdatePassword(model2); return(RedirectToAction("SearchMember", "Member")); } catch { ViewBag.Msg = "不可為空白"; return(View()); } }