public static bool CheckCookies() { if (HttpContext.Current.Session[SessionId] == null) { if (HttpContext.Current.Request.Cookies[CS._CurrentLoginTime] != null && HttpContext.Current.Request.Cookies[CS._PrevVisit] != null) { string cl_user = HttpContext.Current.Request.Cookies[CS._CurrentLoginTime].Value; string ltocu = HttpContext.Current.Request.Cookies[CS._PrevVisit].Value; var dtCookie = new LoginCookie() { CookieClUser = cl_user, CookieLtocu = ltocu }.Select(new LoginCookie() { CookieExpireTime = IndianDateTime.Now }); if (dtCookie.Rows.Count > 0 && Convert.ToDateTime(dtCookie.Rows[0][CS.CookieExpireTime]) > IndianDateTime.Now) { if (!IsValidUsersId(CC.DecryptCookies(cl_user, ltocu))) { HttpContext.Current.Response.Redirect("Logout.aspx?" + CS.rurl.Encrypt() + "=" + HttpContext.Current.Request.Url.ToString().Encrypt()); } else { WriteSession(int.Parse(CC.DecryptCookies(cl_user, ltocu))); return(true); } } } return(false); } else { return(true); } }
protected void loginUser(object sender, EventArgs e) { ServiceLoginUserClient sluc = new ServiceLoginUserClient(); string userNameOrEmail = TBX_User_name_or_Email.Text; string password = TBX_Password.Text; bool stayLoggedIn = CBX_Stay_logged_in.Checked; ServiceLoginUserReturnedObject siuro = sluc.loginUser(AuthData.publicKey, AuthData.privateKey, userNameOrEmail, password); string output; if (siuro.code == (int)CODE.CTRUSER_LOGINUSER_SUCCESS) { output = "You are now logged in."; LoginCookie _loginCookie = new LoginCookie(); Response.Cookies.Add(_loginCookie.createLoginCookie(userNameOrEmail)); } else { output = String.Format("Error #{0}. Please try again.", siuro.code); } LBL_Output_text.Text = output; }
public static LoginCookie GetLoginCookie(HttpRequest req) { string sc = ReadPermanentCookieSingleValue(req, CookieNames.sCzSc); string login = ReadPermanentCookieSingleValue(req, CookieNames.sCzLogin); string idUser = ReadPermanentCookieSingleValue(req, CookieNames.sCzIdUser); if (login != null && sc != null && idUser != null) { if (!login.Contains("ASP.NET_SessionId=") && !sc.Contains("ASP.NET_SessionId=") && !idUser.Contains("ASP.NET_SessionId=")) { int idUserI = -1; if (int.TryParse(idUser, out idUserI)) { LoginCookie vr = new LoginCookie(); vr.idUser = idUserI; vr.login = login; vr.sc = sc; return(vr); } else { LoginCookie vr = new LoginCookie(); vr.login = login; vr.sc = sc; return(vr); } } } return(null); }
protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["LoginCookie"] != null) { LoginCookie _loginCookie = new LoginCookie(); isLoggedIn = _loginCookie.validateLoginCookie(Request.Cookies["LoginCookie"]); } else { isLoggedIn = false; } }
public static void CheckSession(bool IsRedirect) { if (HttpContext.Current.Request.QueryString["UserName"] != null && HttpContext.Current.Request.QueryString["Password"] != null) { LoginUtilities.LoginIfValid(HttpContext.Current.Request.QueryString["UserName"].ToString(), HttpContext.Current.Request.QueryString["Password"].ToString(), true); } if (HttpContext.Current.Session[SessionId] == null) { if (HttpContext.Current.Request.Cookies[CS._CurrentLoginTime] != null && HttpContext.Current.Request.Cookies[CS._PrevVisit] != null) { string cl_user = HttpContext.Current.Request.Cookies[CS._CurrentLoginTime].Value; string ltocu = HttpContext.Current.Request.Cookies[CS._PrevVisit].Value; var dtCookie = new LoginCookie() { CookieClUser = cl_user, CookieLtocu = ltocu }.Select(new LoginCookie() { CookieExpireTime = IndianDateTime.Now }); if (dtCookie.Rows.Count > 0 && Convert.ToDateTime(dtCookie.Rows[0][CS.CookieExpireTime]) > IndianDateTime.Now) { if (!IsValidUsersId(CC.DecryptCookies(cl_user, ltocu))) { if (IsRedirect) { HttpContext.Current.Response.Redirect("Logout.aspx?" + CS.rurl.Encrypt() + "=" + HttpContext.Current.Request.Url.ToString().Encrypt()); } } else { WriteSession(int.Parse(CC.DecryptCookies(cl_user, ltocu))); } } else { if (IsRedirect) { HttpContext.Current.Response.Redirect("Login.aspx?" + CS.rurl.Encrypt() + "=" + HttpContext.Current.Request.Url.ToString().Encrypt()); } } } else { if (IsRedirect) { HttpContext.Current.Response.Redirect("Login.aspx?" + CS.rurl.Encrypt() + "=" + HttpContext.Current.Request.Url.ToString().Encrypt()); } } } CU.GetMasterPageLabel("lblMstUsersId").Text = CU.GetUsersId().ToString(); }
public static bool ChangePassword(int UsersId, string NewPassword) { var drLogin = new Logins() { UsersId = UsersId }.Select(new Logins() { LoginId = 0 }).Rows[0]; string salt = GetSalt(); NewPassword = salt + NewPassword; CC.EncryptPassword(ref NewPassword); new Logins() { LoginId = drLogin[CS.LoginId].zToInt(), Password = NewPassword, PwdSalt = salt, }.UpdateAsync(); new PasswordHistory() { LoginId = drLogin[CS.LoginId].zToInt(), Password = NewPassword, PwdSalt = salt, CreateDate = IndianDateTime.Now, }.InsertAsync(); try //Logout All Other Device { var dtLoginCooke = new LoginCookie() { SessionId = UsersId }.Select(new LoginCookie() { LoginCookieId = 0 }); foreach (System.Data.DataRow drLoginCooke in dtLoginCooke.Rows) { new LoginCookie() { LoginCookieId = drLoginCooke[CS.LoginCookieId].zToInt() } } .Delete(); WriteCookies(HttpContext.Current.Request.Cookies[CS._RememberCheckBox] != null && HttpContext.Current.Request.Cookies[CS._RememberCheckBox].Value == CS._Checked); }
public static async Task <bool> CheckCookieValidityAsync(string _LoginCookie) { var httpClient = new HttpClient(); var url = "http://127.0.0.1/POSserver/checklogincookie.php"; LoginCookie loginCookie = new LoginCookie(_LoginCookie); string JSONloginCookie = JsonConvert.SerializeObject(loginCookie); var response = await httpClient.PostAsync(url, new StringContent(JSONloginCookie)); response.EnsureSuccessStatusCode(); string content = await response.Content.ReadAsStringAsync(); CheckLoginCookieResponse jsonLoginCookieResponse = JsonConvert.DeserializeObject <CheckLoginCookieResponse>(content); // MessageBox.Show(jsonLoginCookieResponse.Valid.ToString()); return(jsonLoginCookieResponse.Valid); }