public bool ValidateUserLDAP(string userName, string password) { try { bool kt = LdapFunction.ValidateUser(userName, password); return(kt); } catch (Exception ex) { return(false); } }
public ActionResult ChangePassword(ChangePasswordModel model) { try { NI10_Employee employee = (Session["EmployeeLogin"] != null) ? (NI10_Employee)Session["EmployeeLogin"] : new NI10_Employee(); bool isADAuthenticate = bool.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["IsADAuthenticate"]); if (isADAuthenticate) { bool isValidateUser = LdapFunction.IsExists(employee.EmployeeCode); if (isValidateUser) { if (!String.IsNullOrEmpty(model.NewPassword)) { if (StaticFunc.EncryptIntranet(model.CurrentPassword) == employee.CurrentPassword) { LdapFunction.ResetPassword(employee.EmployeeCode, model.NewPassword); employee.CurrentPassword = StaticFunc.EncryptIntranet(model.NewPassword); Session["EmployeeLogin"] = employee; } else { TempData["error"] = "Mật khẩu cũ không trùng khớp"; } } } else { TempData["error"] = "Không tìm thấy tài khoản của bạn"; } } } catch (Exception ex) { if (ex.ToString().Contains("The password does not meet the password policy requirements")) { TempData["error"] = "Mật khẩu không được chứa họ,tên,tên đệm"; } else { TempData["error"] = ex.ToString(); } } if (TempData["error"] != null) { return(Redirect("/User/Profile")); } else { TempData["success"] = "Cập nhập thành công!"; return(Redirect("/User/Login/?returnUrl=/")); } }
public ActionResult Login(LoginModel model) { string result = "", actiontype = ""; NI10_Employee employee = new SqlNI10_EmployeeDao().GetSingleByCustomDataSource(new object[] { "@employeeCode", model.LoginName }, "[dbo].[NI10_Employee_GetEmployeeInfo]"); if (employee != null) { if (isADAuthenticate) { if (ValidateUserLDAP(model.LoginName, model.PassWord.Trim()) == false) { UserPrincipal userPrincipal = LdapFunction.GetUserPrincipal(model.LoginName); if (userPrincipal != null) { if (userPrincipal.AccountExpirationDate != null) { actiontype = "1"; result = "Tài khoản đã nghỉ việc. Vui lòng liên hệ support để hỗ trợ"; } else if (userPrincipal.AccountLockoutTime != null) { actiontype = "1"; result = "Tài khoản của bạn đã bị khóa. Vui lòng liên hệ support để hỗ trợ"; Session["countLoginFail"] = "0"; } else { result = "Username hoặc password không đúng. Vui lòng kiểm tra lại"; actiontype = "1"; } } TempData["error"] = result; } else { actiontype = "0"; this.FillLoginInfo(employee.JobTitle, model.LoginName.Trim(), employee.FullName, employee.EmployeeCode, "", false, "", "", employee.Avatar, "false", 0, StaticFunc.EncryptIntranet(model.PassWord.Trim()), employee.EmailAddress); if (model.ReturnUrl == null) { return(Redirect("/TankList/Home")); } return(Redirect(model.ReturnUrl)); } } } return(View()); }