public ActionResult ResetPass() { try { using (var db = new KhaoThiDBContext()) { var account = db.Accounts.Find("Admin"); account.Password = strPro.GetMD5("123456"); account.ConfirmPassword = account.Password; db.SaveChanges(); } } catch { } return(RedirectToAction("Index", "Home_Ad")); }
public ActionResult Login(Accounts acc, string returnUrl) { StringProcess strPro = new StringProcess(); try { if (!string.IsNullOrEmpty(acc.UserName) && !string.IsNullOrEmpty(acc.Password)) { using (var db = new QuanLyDoAnDbContext()) { var passToMD5 = strPro.GetMD5(acc.Password); var account = db.Accounts.Where(m => m.UserName.Equals(acc.UserName) && m.Password.Equals(passToMD5)); if (account.Count() == 1) { FormsAuthentication.SetAuthCookie(acc.UserName, false); Session["idUser"] = acc.UserName; Session["roleUser"] = acc.RoleId; Session["StudentCode"] = account.FirstOrDefault().StudentCode; Session["TeacherCode"] = account.FirstOrDefault().TeacherCode; Response.Cookies.Add(new HttpCookie("userCookie", acc.UserName)); Response.Cookies.Add(new HttpCookie("roleCookie", acc.RoleId)); return(RedirectToLocal(returnUrl)); } ModelState.AddModelError("", "Thông tin đăng nhập chưa chính xác"); } } ModelState.AddModelError("", "Username and password is required."); } catch { ModelState.AddModelError("", "Hệ thống đang được bảo trì, vui lòng liên hệ với quản trị viên"); } return(View(acc)); }
public ActionResult Create([Bind(Include = "AccountId,UserName,Email,Password,ConfirmPassword,RoleId,StudentCode,TeacherCode")] Accounts accounts) { string strMD5 = strPro.GetMD5(accounts.Password); if (accounts.Password == accounts.ConfirmPassword) { accounts.Password = strMD5; accounts.ConfirmPassword = strMD5; } if (ModelState.IsValid) { db.Accounts.Add(accounts); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoleId = new SelectList(db.Roles, "RoleId", "RoleName", accounts.RoleId); ViewBag.StudentCode = new SelectList(db.Students, "StudentCode", "StudentName", accounts.StudentCode); ViewBag.TeacherCode = new SelectList(db.Teachers, "TeacherCode", "TeacherName", accounts.TeacherCode); return(View(accounts)); }
public ActionResult Create([Bind(Include = "UserName,Password,RoleID,ConfirmPassword")] Account account) { try { if (ModelState.IsValid) { var md5Pass = strPro.GetMD5(account.Password); account.Password = md5Pass; account.ConfirmPassword = md5Pass; db.Accounts.Add(account); db.SaveChanges(); return(RedirectToAction("Index")); } } catch { ModelState.AddModelError("", "Username is exist. Please try again."); ViewBag.ListRole = db.Roles.ToList(); } return(View(account)); }
public ActionResult Create([Bind(Include = "UserName,Password,ConfirmPassWord,Email,CreationTime,EmailConfirmed,IsDelete,DeleteTime,RoleID")] Accounts accounts) { accounts.CreationTime = DateTime.Now; accounts.EmailConfirmed = false; accounts.IsDelete = false; string strMD5 = strPro.GetMD5(accounts.Password); if (accounts.Password == accounts.ConfirmPassWord) { accounts.Password = strMD5; accounts.ConfirmPassWord = strMD5; } if (ModelState.IsValid) { db.Accounts.Add(accounts); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(accounts)); }