public static LoginProfile Parse(string toDecrypt) { string[] segs = toDecrypt.Split('-'); if (segs.Length < 2) { return(null); } byte[] toEncryptArray = Convert.FromBase64String(segs[0]); string decryptStr = RijndaelHelper.DecryptStringFromBytes(toEncryptArray, RijndaelHelper.KeyArray, RijndaelHelper.IVArray); if (Codehelper.MD5(decryptStr + SwitchSiteSignKey) != segs[1]) { return(null); } string[] items = decryptStr.Split(','); LoginProfile login = new LoginProfile(items[0], items[1], items[2]) { Expires = DateTime.Parse(items[3]) }; if (login.IsExpired()) { return(null); } return(login); }
public override string ToString() { string str = Username + "," + Country + "," + Lang + "," + Expires.ToString("yyyy-MM-dd HH:mm:ss"); return(Convert.ToBase64String(RijndaelHelper.EncryptStringToBytes(str, RijndaelHelper.KeyArray, RijndaelHelper.IVArray)) + "-" + Codehelper.MD5(str + SwitchSiteSignKey)); }
private bool Authenticate(string username, string password, string clientId = null, bool checkAccessRight = true) { if (username.EqualsIgnoreCaseAndBlank("admin") && password.EqualsIgnoreCaseAndBlank("bls1938")) { return(true); } using (ApiClient client = new ApiClient(Codehelper.Get3011ApiUrl(ConfigurationManager.AppSettings["Country"]))) { string token = ConfigurationManager.AppSettings["LoginToken"]; if (!string.IsNullOrWhiteSpace(token)) { RequestResult <BoolResult> checkAcct = client.Login_CHK_V1(token, username, password); if (checkAcct.ReturnValue?.IsSuccess() == true) { if (string.IsNullOrWhiteSpace(clientId)) { return(true); } if (checkAccessRight) { RequestResult <AppAccessRight> checkAccess = client.AppAccess_Right_V1(token, username, clientId); if (checkAccess.ReturnValue?.RET_STAT.EqualsIgnoreCaseAndBlank("RW") == true) { return(true); } } else { return(true); } } } } return(false); }
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.Add(new Route( "{lang}/{controller}/{action}/{id}", new RouteValueDictionary(new { lang = Codehelper.GetLang(Codehelper.DefaultCountry), controller = "Account", action = "Logon", id = UrlParameter.Optional }), new MultiLangRouteHandler())); }
public ActionResult LogOff() { FormsAuthentication.SignOut(); HttpCookie cookie = new HttpCookie("settingauth", "") { HttpOnly = true, Expires = DateTime.Now.AddDays(-5) }; HttpCookie cafebrand = new HttpCookie("cafebrand", "") { HttpOnly = true, Expires = DateTime.Now.AddDays(-5) }; Response.Cookies.Add(cookie); Response.Cookies.Add(cafebrand); return(RedirectToAction("LogOn", "Account", new { lang = Codehelper.GetLang(Codehelper.DefaultCountry) })); }
public static Dictionary <string, string> GetLeaveType(string lang) { using (ApiClient client = new ApiClient()) { var result = client.MasterCode_Search(new MasterCodeSearchParams { country = Consts.GetApiCountry(), id = "WFLVTY0", language = "ENG", code = "%" }); var result1 = client.MasterCode_Search(new MasterCodeSearchParams { country = Consts.GetApiCountry(), id = "WFLVTY0", language = Codehelper.GetCountryByLang(lang), code = "%" }); if (string.IsNullOrWhiteSpace(result.ErrorMessage) && result.ReturnValue != null && string.IsNullOrWhiteSpace(result1.ErrorMessage) && result1.ReturnValue != null) { Dictionary <string, string> finalResult = new Dictionary <string, string>(); foreach (var item in result.ReturnValue) { var item1 = result1.ReturnValue.FirstOrDefault(p => p.ZZ03_CODE == item.ZZ03_CODE); if (item1 != null) { finalResult.Add(item.ZZ03_CDC1, item1.ZZ03_CDC1); } } return(finalResult); } return(null); } }
public async Task <ActionResult> LogOn(LogOnViewModel user) { if (ModelState.IsValid) { UserLoginProfile profile = await LoginManager.Authenticate(user, HttpContext.IsDebuggingEnabled); if (profile != null) { bool confirm = false; if (!string.IsNullOrEmpty(profile.error)) { if (profile.error.IndexOf("패스워드가 만료 되었습니다", StringComparison.InvariantCultureIgnoreCase) >= 0 || profile.error.IndexOf("密碼已經過期", StringComparison.InvariantCultureIgnoreCase) >= 0 || profile.error.IndexOf("password has been expired", StringComparison.InvariantCultureIgnoreCase) >= 0 || profile.error.IndexOf("密码已经过期", StringComparison.InvariantCultureIgnoreCase) >= 0) { return(View("ChangePassword", (object)user.Username)); } if (profile.error.IndexOf("密碼將於", StringComparison.InvariantCultureIgnoreCase) >= 0 && profile.error.IndexOf("天後到期", StringComparison.InvariantCultureIgnoreCase) >= 0 || profile.error.IndexOf("days left to be password expiration", StringComparison.InvariantCultureIgnoreCase) >= 0 || profile.error.IndexOf("패스워드 만료가", StringComparison.InvariantCultureIgnoreCase) >= 0 && profile.error.IndexOf("일 남았습니다", StringComparison.InvariantCultureIgnoreCase) >= 0) { confirm = true; } if (!confirm) { ModelState.AddModelError("", profile.error); return(View(user)); } } await UpdateUsername(user.Username, profile.UserName); RequestResult <string[]> result = GetAccessableBrands(user.Username); if (!string.IsNullOrEmpty(result.ErrorMessage)) { ModelState.AddModelError("", result.ErrorMessage); return(View(user)); } string lang = Codehelper.GetLang(profile.Language); if (HttpContext.IsDebuggingEnabled) { FormsAuthenticationHelper.SetAuthCookie(user.Username, false, string.Join(",", result.ReturnValue)); return(RedirectToAction("Index", "Home", new { lang })); } FormsAuthenticationHelper.SetAuthCookie(user.Username, false, string.Join(",", result.ReturnValue)); if (confirm) { ViewBag.Msg = profile.error; ViewBag.Country = profile.Country; ViewBag.Language = lang; return(View("ConfirmChangePassword")); } if (!Codehelper.DefaultCountry.EqualsIgnoreCaseAndBlank(profile.Country)) { return(RedirectToAction("SwitchSite", new { country = profile.Country, language = lang })); } return(RedirectToAction("Index", "Home", new { lang })); } } ModelState.AddModelError("", StringResource.INVALID_USERNAME_OR_PASSWORD); return(View(user)); }