protected bool createIdentificationCookie(int cntval, string Role) { string id = string.Format("Id: {0} Uri: {1}", Guid.NewGuid(), HttpContext.Current.Request.Url); using (Utils utility = new Utils()) { utility.MethodStart(id, System.Reflection.MethodBase.GetCurrentMethod()); } try { string cookieCode = Bill_Sys_Utility.GenerateOtp(6); string cookieEncryptionKey = System.Configuration.ConfigurationManager.AppSettings.Get("COOKIE_ENCRYPT_KEY"); string encryptedCookieCode = Bill_Sys_Utility.ComputeHMACSHA1(cookieCode, cookieEncryptionKey); HttpCookie cookie2 = Request.Cookies["GREENBILLS_DETECTION"]; cookie2.Expires = DateTime.Now.AddYears(1); cookie2[cntval.ToString()] = encryptedCookieCode; Response.Cookies.Add(cookie2); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, txtUserName.Text, DateTime.Now, DateTime.Now.AddMinutes(30), true, Role, FormsAuthentication.FormsCookiePath); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } Response.Cookies.Add(cookie); if (UpdateCookieCode(txtUserName.Text, cookieCode)) { return(true); } else { return(false); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); using (Utils utility = new Utils()) { utility.MethodEnd(id, System.Reflection.MethodBase.GetCurrentMethod()); } string str2 = "Error Request=" + id + ".Please share with Technical support."; base.Response.Redirect("Bill_Sys_ErrorPage.aspx?ErrMsg=" + str2); return(false); } //Method End using (Utils utility = new Utils()) { utility.MethodEnd(id, System.Reflection.MethodBase.GetCurrentMethod()); } }
protected bool createIdentificationCookie(string role) { string id = string.Format("Id: {0} Uri: {1}", Guid.NewGuid(), HttpContext.Current.Request.Url); using (Utils utility = new Utils()) { utility.MethodStart(id, System.Reflection.MethodBase.GetCurrentMethod()); } try { string cookieCode = Bill_Sys_Utility.GenerateOtp(6); string cookieEncryptionKey = System.Configuration.ConfigurationManager.AppSettings.Get("COOKIE_ENCRYPT_KEY"); string encryptedCookieCode = Bill_Sys_Utility.ComputeHMACSHA1(cookieCode, cookieEncryptionKey); if (Request.Cookies["GREENBILLS_DETECTION"] == null) { HttpCookie cookieCnt = new HttpCookie("LOGIN_COUNT", "0"); cookieCnt.Expires = DateTime.Now.AddYears(1); cookieCnt.Value = "0"; Response.Cookies.Add(cookieCnt); HttpCookie cookie1 = new HttpCookie("GREENBILLS_DETECTION"); cookie1.Expires = DateTime.Now.AddYears(1); cookie1[cookieCnt.Value] = encryptedCookieCode; Response.Cookies.Add(cookie1); } else { HttpCookie cookie2 = Request.Cookies["GREENBILLS_DETECTION"]; HttpCookie cookieCnt = Request.Cookies["LOGIN_COUNT"]; if (cookieCnt == null) { cookieCnt = new HttpCookie("LOGIN_COUNT", "0"); cookieCnt.Value = (Convert.ToInt32(cookie2.Values.Count) - 1).ToString(); cookieCnt.Expires = DateTime.Now.AddYears(1); } int allowCount = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings.Get("MAX_USER_ALLOW")); if (Convert.ToInt32(cookieCnt.Value) < allowCount - 1) { cookie2.Expires = DateTime.Now.AddYears(1); cookieCnt.Value = (Convert.ToInt32(cookieCnt.Value) + 1).ToString(); cookie2[cookieCnt.Value] = encryptedCookieCode; Response.Cookies.Add(cookie2); Response.Cookies.Add(cookieCnt); } else { return(createIdentificationCookie(GetLastIndex(), role)); } } if (UpdateCookieCode(txtUserName.Text, cookieCode)) { return(true); } else { return(false); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); using (Utils utility = new Utils()) { utility.MethodEnd(id, System.Reflection.MethodBase.GetCurrentMethod()); } string str2 = "Error Request=" + id + ".Please share with Technical support."; base.Response.Redirect("Bill_Sys_ErrorPage.aspx?ErrMsg=" + str2); return(false); } //Method End using (Utils utility = new Utils()) { utility.MethodEnd(id, System.Reflection.MethodBase.GetCurrentMethod()); } }