public IActionResult Log([Bind("username, password")] User user) { var r = _context.users.Where(m => (m.username == user.username && m.password == StringProcessing.CreateMD5Hash(user.password))).ToList(); if (r.Count == 0) { SetAlert("Login fail - Username or password wrong !", "warning"); return(RedirectToAction("Login", "Auth")); } var str = JsonConvert.SerializeObject(r[0]); HttpContext.Session.SetString("user", str); if (r[0].rule == 1) { //var url = Url.RouteUrl("Admin", new { Controller = "Home", action = "Index", area = "Admin" }); SetAlert("Login success - Admin", "success"); //return Redirect(url); return(RedirectToAction("Index", "Home", new { area = "Admin" })); } SetAlert("Login success - User", "success"); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> SignUp(RegisterViewModel model) { if (ModelState.IsValid) { var allUser = _context.users.ToList(); foreach (var item in allUser) { if (item.username == model.username) { SetAlert("User already existed in system", "warning"); return(View(model)); } } var m_username = model.username.Trim().Length; if (m_username <= 5 || m_username > 32) { ModelState.AddModelError("", "User name must be between 6 - 32 character."); SetAlert("Username invalid", "warning"); return(View(model)); } var m_pwd = model.password.Trim(); var valid_pwd = ValidatePassword(m_pwd); if (valid_pwd.Count != 0) { foreach (var item in valid_pwd) { if (item == -1) { ModelState.AddModelError("", "Password must be between 8-32 character."); } else if (item == -2) { ModelState.AddModelError("", "Password must have least one uppercase letter."); } else if (item == -3) { ModelState.AddModelError("", "Password must have least one lowercase letter."); } else if (item == -4) { ModelState.AddModelError("", "Password must have least one number."); } else if (item == -5) { ModelState.AddModelError("", "Password must have least one special letter."); } } SetAlert("Password invalid", "warning"); return(View(model)); } var user = new User { username = model.username, displayname = model.username, email = model.email, password = StringProcessing.CreateMD5Hash(model.password), rule = 0 }; _context.Add <User>(user); await _context.SaveChangesAsync(); var str = JsonConvert.SerializeObject(user); HttpContext.Session.SetString("user", str); SetAlert("Sign up success", "success"); return(RedirectToAction("Index", "Home")); } SetAlert("Register fail", "danger"); return(View(model)); }
public IActionResult Login([Bind("TaiKhoan,MatKhau")] NguoiDungModel nguoidung) { var r = _context.NguoiDung.Where(x => (x.TaiKhoan == nguoidung.TaiKhoan && x.MatKhau == StringProcessing.CreateMD5Hash(nguoidung.MatKhau) && x.TinhTrang == true)).ToList(); if (r.Count == 0) { Message = "Tài Khoản Hoặc mật khẩu không chính xác"; return(RedirectToAction("Index")); } nguoidung.NguoiDung = r[0].NguoiDung; var thongtin = JsonConvert.SerializeObject(nguoidung); HttpContext.Session.SetString("nguoidung", thongtin); if (r[0].PhanQuyen == 1) { admin = r[0].NguoiDung; var url = Url.RouteUrl("Admin", new { controller = "Home", action = "Index", area = "Admin" }); return(Redirect(url)); id = r[0].Id; } user = r[0].NguoiDung; id = r[0].Id; return(RedirectToAction("Index", "Home")); }
public IActionResult Login([Bind("UserName,Password")] UserModel member) { var r = _context.UserModel.Where(m => (m.UserName == member.UserName && m.Password == StringProcessing.CreateMD5Hash(member.Password))).ToList(); var info = _context.UserModel.Where(m => m.UserName == member.UserName).ToList(); if (r.Count == 0) { return(View("Index")); } //var str = JsonConvert.SerializeObject(member); HttpContext.Session.SetString("username", member.UserName); HttpContext.Session.SetInt32("id", info[0].ID); if (r[0].Loai == "0") { var url = Url.RouteUrl("areas", new { Controller = "SanPham", action = "Index", area = "Admin" }); return(Redirect(url)); } return(RedirectToAction("Index", "Pages")); }
public IActionResult Login([Bind("AccountName, Password")] AccountModel accountModel) { var r = _context.Account.Where(m => (m.AccountName == accountModel.AccountName && m.Password == StringProcessing.CreateMD5Hash(accountModel.Password))).ToList(); if (r.Count == 0) { return(View("Index")); } var str = JsonConvert.SerializeObject(accountModel); HttpContext.Session.SetString("user", str); if (r[0].Rule == 0) { var url = Url.RouteUrl("areas", new { controller = "Home", action = "Index", area = "Admin" }); return(Redirect(url)); } return(RedirectToAction("Index", "Home")); }
public IActionResult Login([Bind("Ten_dang_nhap", "Mat_khau")] TaiKhoanModel taikhoan) { var r = _context.TaiKhoanModel.Where(m => (m.Ten_dang_nhap == taikhoan.Ten_dang_nhap && m.Mat_khau == StringProcessing.CreateMD5Hash(taikhoan.Mat_khau))).ToList(); if (r.Count == 0) { return(View("Error")); } var str = JsonConvert.SerializeObject(taikhoan); HttpContext.Session.SetString("user", str); if (r[0].Loai_tai_khoan == 0) { var url = Url.RouteUrl("areas", new { Controller = "Home", action = "Index", area = "admin" }); return(Redirect(url)); } return(RedirectToAction("Index", "Home")); }
public IActionResult Index([Bind("TaiKhoan", "MatKhau")] AdminModel member) { var r = _context.tb_Admin.Where(m => (m.TaiKhoan.Equals(member.TaiKhoan) && m.MatKhau.Equals(StringProcessing.CreateMD5Hash(member.MatKhau))) && m.TrangThai == true).ToList(); if (r.Count > 0) { var str = JsonConvert.SerializeObject(member); HttpContext.Session.SetString("user", str); JObject us = JObject.Parse(HttpContext.Session.GetString("user")); AdminModel mem = new AdminModel(); mem.TaiKhoan = us.SelectToken("TaiKhoan").ToString(); mem.MatKhau = us.SelectToken("MatKhau").ToString(); return(View(mem)); } return(RedirectToAction("Login", "HomePage")); }