public ActionResult Index(LoginModel loginModel) { int n = u.CreateUser(loginModel.UserName, MD5Encrypt16(loginModel.PassWord, new UTF8Encoding())); if (n == 0) { ModelState.AddModelError("", "用户名存在"); return View(loginModel); } return RedirectToAction("Index", "Home"); }
public ActionResult Index(LoginModel loginModel) { User user = u.GetUser(loginModel.UserName); if (user != null && user.pass == MD5Encrypt16(loginModel.PassWord, new UTF8Encoding())) { HttpContext.Session["ss_User"] = user; return RedirectToAction("Index", "Main"); } else { ModelState.AddModelError("", "用户名或密码错误"); } return View(loginModel); }