public ActionResult Login(FormCollection f) { string Username = f["username"].ToString(); string Password = f["Password"].ToString(); NhanVienViewModel account = _nhanVienBus.Login(Username, Md5Encode.EncodePassword(Password)); if (account != null) { if (account.trangThai != true) { TempData["notify"] = "Tài khoản của bạn đã bị khóa!!!"; } else { string aut = _nhanVienBus.Authority(account); Decentralization(account.maNhanVien.ToString(), aut); Session["Account"] = account; userName = Username; } } else { TempData["notify"] = "Username hoặc Password không đúng!!!"; } return(RedirectToAction("Index")); }
public ActionResult Create(User user, HttpPostedFileBase image_avatar, bool status_mi) { if (ModelState.IsValid) { Md5Encode md5 = new Md5Encode(); user.Password = md5.EncodeMd5Encrypt(user.Password); user.CreatedAt = DateTime.Now; bool tus; if (status_mi == true) { tus = true; } else { tus = false; } var checkemail = db.User.Count(x => x.Email == user.Email); if (checkemail > 0) { ViewBag.erroremail = "Email Đăng Kí Đã Tồn Tại"; } else { if (image_avatar != null) { var filename = Path.GetFileName(image_avatar.FileName); var path = Path.Combine(Server.MapPath("~/Upload/Images"), filename); image_avatar.SaveAs(path); user.Image = "/Upload/Images/" + image_avatar.FileName; } else { user.Image = "/Upload/Default/man-avatar.jpg"; } user.Status = tus; db.User.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(user)); }
public JsonResult CheckPassword(string matkhaucu) { var isDuplicate = false; var mk = Md5Encode.EncodePassword(matkhaucu).ToLower(); foreach (var user in _nhanVienBus.GetAllPassword(((NhanVienViewModel)(Session["Account"])).maNhanVien)) { if (user.PassWord.ToLower() != mk) { isDuplicate = true; } } var jsonData = new { isDuplicate }; return(Json(jsonData, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> UpdatePassword(String matkhaumoi, string matkhaucu) { NhanVien editEmployee = (NhanVien)await _nhanVienBus.Find(((NhanVienViewModel)(Session["Account"])).maNhanVien); try { await _nhanVienBus.UpdatePassword(editEmployee, Md5Encode.EncodePassword(matkhaumoi)); SetAlert("Bạn đã cập nhật mật khẩu thành công!!!", "success"); } catch { SetAlert("Đã xảy ra lỗi! Bạn hãy cập nhật lại", "error"); return(RedirectToAction("UpdatePassword")); } return(RedirectToAction("Index")); }
public ActionResult postChangePassword(string pass_old, string pass_new, string pass_new_repeat) { int id = Convert.ToInt32(Session["UserID"]); var old = db.User.SingleOrDefault(x => x.UserID == id); Md5Encode md5 = new Md5Encode(); var pass_old_item = old.Password; if (pass_old_item != md5.EncodeMd5Encrypt(pass_old)) { TempData["errordisplaypass"] = "******"; TempData["error_pass_old"] = "Mật khẩu cũ không chính xác"; } else { if (pass_new.Length >= 6 && pass_new_repeat.Length >= 6) { if (pass_new_repeat == pass_new) { User user = db.User.Find(id); var pass_new_md5 = md5.EncodeMd5Encrypt(pass_new); user.Password = pass_new_md5; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); TempData["displaypass"] = "******"; TempData["success_pass"] = "******"; return(RedirectToAction("getChangePassword")); } else { TempData["errordisplaypassnew"] = "display:block!important"; TempData["error_pass_repeat"] = "Mật khẩu mới không khớp nhau"; } } else { TempData["errorlengthdis"] = "display:block!important"; TempData["errorlengthpass"] = "******"; } } return(RedirectToAction("getChangePassword")); }
public async Task Create(object model) { var nhanVien = new NhanVien(); NhanVienViewModel input = (NhanVienViewModel)model; nhanVien.TenNhanvien = input.tenNhanVien; nhanVien.DiaChi = input.diaChi; nhanVien.SoDienThoai = input.soDienThoai; nhanVien.Email = input.email; nhanVien.CMND = input.CMND; nhanVien.UserName = input.userName; nhanVien.PassWord = Md5Encode.EncodePassword(input.password); nhanVien.TrangThai = true; nhanVien.MaChucVu = input.maChucVu; nhanVien.Avatar = input.avatar; await _nhanVienRepo.InsertAsync(nhanVien); }
public ActionResult Login(string email, string password) { Md5Encode md5 = new Md5Encode(); var passmd5 = md5.EncodeMd5Encrypt(password); var login = db.User.SingleOrDefault(x => x.Email == email && x.Password == passmd5 && x.Status == true); if (login != null) { Session["UserID"] = login.UserID; Session["Username"] = login.Username; Session["Email"] = login.Email; Session["Password"] = login.Password; Session["Image"] = login.Image; return(Redirect("~/admin/home")); } else { ViewBag.error = "Tên Tài Khoản Hoặc Mật Khẩu Không Đúng"; } return(View()); }
public Result Register(string name, string password) { string encoded_pwd = Md5Encode.Encode(password); User user = new User { username = name, pwd = encoded_pwd, }; using (var db = new DBModel()) { db.users.Add(user); var result = db.SaveChangesAsync().IsCompleted; if (result == false) { return(ResultUtil.Error(ResultEnum.ResultType.HAVE_OCCUPIED)); } } return(ResultUtil.Success()); }
public Md5EncodeTeste() { this.md5Encode = new Md5Encode(); }