/// <summary> /// Hàm lưu mảng giá trị config /// </summary> /// <param name="strGroup">Key nhóm cần lưu</param> /// <param name="dic">Mảng giá trị config</param> /// <returns></returns> static public bool SetGroupValue(string strGroup, Dictionary <string, string> dic) { if (dic == null) { return(false); } if (dic.Count == 0) { return(false); } Xmlconfig xmlcg = new Xmlconfig(DDefault.PathFileConfig, true); foreach (var d in dic) { xmlcg.Settings[strGroup][d.Key].Value = DHash.Encrypt(d.Value, KeyPass); } try { xmlcg.Save(DDefault.PathFileConfig); return(true); } catch { return(false); } }
public ActionResult DecryptPass(string typepass, string content, string keypass) { if (typepass == "d") { ViewBag.StrEncrypt = content; if (string.IsNullOrEmpty(keypass)) { ViewBag.StrDecrypt = DHash.Decrypt(content); } else { ViewBag.StrDePass = keypass; ViewBag.StrDecrypt = DHash.Decrypt(content, keypass); } } else if (typepass == "e") { ViewBag.StrDecrypt = content; if (string.IsNullOrEmpty(keypass)) { ViewBag.StrEncrypt = DHash.Encrypt(content); } else { ViewBag.StrEnPass = keypass; ViewBag.StrEncrypt = DHash.Encrypt(content, keypass); } } return(View("__Cms/Config/DecryptPass")); }
public static void SetCookie(string key, object value, int timehour = 5) { // create a cookie HttpCookie newCookie = new HttpCookie(key, DHash.Encrypt(value.ToString())); if (timehour == 5) { timehour = DDefault.HourCookiesSession; } newCookie.Expires = DateTime.Now.AddHours(timehour); newCookie.HttpOnly = true; HttpContext.Current.Response.Cookies.Add(newCookie); }
/// <summary> /// Hàm lưu giá trị config /// </summary> /// <param name="strKey">Key thuộc tính</param> /// <param name="strValue">Giá trị lưu (string)</param> /// <returns></returns> static public bool SetValue(string strKey, string strValue) { Xmlconfig xmlcg = new Xmlconfig(DDefault.PathFileConfig, true); xmlcg.Settings[strKey].Value = DHash.Encrypt(strValue, KeyPass); try { xmlcg.Save(DDefault.PathFileConfig); return(true); } catch { return(false); } }
/// <summary> /// Hàm kiểm tra dành cho đăng nhập /// <para>Được sử riêng cho trang Login</para> /// </summary> /// <param name="username">Tài khoản</param> /// <param name="password">Mật khẩu</param> /// <param name="remember">Ghi nhớ tài khoản bằng Cookie</param> /// <returns>bool</returns> public static bool CheckLogin(string username, string password, bool remember = false) { if (username == DDefault.SAdminID && password == DDefault.SAdminPW) { //Setup quyền cho Supper Admin SetCookie("DUser", DDefault.SAdminID); ReloadInfoUser(); if (remember) { SetCookie(DDefault.NameCookieRemember, username, 24 * DDefault.DayCookiesLogin); } else { ClearCookie(DDefault.NameCookieRemember); } return(true); } //Check tài khoàn đăng nhập = database thông thường else { DBAdmin db = new DBAdmin(); password = DHash.Encrypt(password); tbUser tbUser = db.tbUsers.Where(p => p.Username == username && p.Password == password).FirstOrDefault(); if (tbUser == null) { return(false); } SetCookie("DUser", tbUser.Username); ReloadInfoUser(); if (remember) { SetCookie(DDefault.NameCookieRemember, username); } else { ClearCookie(DDefault.NameCookieRemember); } return(true); } }