public static int InvalidPasswordAttempts(HttpSessionStateBase session, int increment = 0) { if (session == null) { return 0; } int retVal = 0; if (session["InvalidPasswordAttempts"] == null) { retVal = retVal + increment; session.Add("InvalidPasswordAttempts", retVal); } else { retVal = Conversion.TryCastInteger(session["InvalidPasswordAttempts"]) + increment; session["InvalidPasswordAttempts"] = retVal; } if (increment > 0) { Log.Warning("{Count} Invalid attempt to sign in from {Host}/{IP} using {Browser}.", retVal, GetUserHostAddress(), GetUserIpAddress(), GetBrowser().Browsers); } return retVal; }
public void SignIn(AdminUser adminUser, HttpSessionStateBase session) { if (adminUser == null) { throw new ArgumentNullException("Invalid authentication"); } formsAuthentication.SetAuthCookie(adminUser.Name, false); session.Add("adminUser", adminUser); }
private void CreateOrUpdateKey(HttpSessionStateBase session) { var data = session[EncryptFieldData] as Tuple<byte[], byte[]>; if (data == null) { provider.GenerateKey(); provider.GenerateIV(); data = new Tuple<byte[], byte[]>(provider.Key, provider.IV); session.Add(EncryptFieldData, data); } key = data.Item1; iv = data.Item2; }
private bool IsAuthorized(HttpSessionStateBase session, HttpRequestBase request, RouteValueDictionary routeDataValues) { iisTraceListener.WriteLine("IsAuthorized"); iisTraceListener.Flush(); bool isAuthorized = false; if (routeDataValues["schoolId"] == null) { return false; } string schoolIdString = routeDataValues["schoolId"] as string; schoolIdString = schoolIdString.Trim().ToLower(); if ((schoolIdString == "dashboard") || (schoolIdString == "error") || (schoolIdString == "login.aspx")) { return true; } int schoolIdInt = 0; if (!int.TryParse(schoolIdString, out schoolIdInt)) { return false; } if (schoolIdInt == 0) { return false; } User user = session["USER"] as User; if (user.Schools == null) { user.Schools = UserAuthentication.GetSchools(user.Email); } foreach (School school in user.Schools) { if (schoolIdInt == school.SchoolId) { isAuthorized = true; break; } } user.AdminPeriods = UserAuthentication.GetAdminPeriodsBySchoolId(schoolIdInt); if (session["ADMINPERIOD"] == null) { session.Add("ADMINPERIOD", user.AdminPeriods.First()); } if (request.QueryString["adminPeriodId"] != null) { string adminPeriodIdString = request.QueryString["adminPeriodId"] as string; adminPeriodIdString = adminPeriodIdString.Trim(); int adminPeriodIdInt = 0; if (int.TryParse(adminPeriodIdString, out adminPeriodIdInt)) { if (adminPeriodIdInt != 0) { foreach (AdminPeriod adminPeriod in user.AdminPeriods) { if (adminPeriodIdInt == adminPeriod.AdminPeriodId) { session.Add("ADMINPERIOD", adminPeriod); break; } } } } } return isAuthorized; }
/// <summary> /// Gets the SessionInfo for the specified session /// </summary> public static SessionInfo ForSession(HttpSessionStateBase session) { var sessionInfo = session[SessionKey] as SessionInfo; if (sessionInfo == null) { sessionInfo = new SessionInfo(); session.Add(SessionKey, sessionInfo); } return sessionInfo; }
/// <summary> /// Add /// </summary> /// <param name="context"></param> /// <param name="sessionState"></param> public static void Add(HttpSessionStateBase sessionState, string sessionKey, object value) { sessionState.Add(sessionKey, value); }
/// <summary> /// Determines whether this instance is ready to post the specified message now. /// </summary> /// <returns><c>true</c> if this instance is ready to post the specified session when; otherwise, <c>false</c>.</returns> /// <param name="session">User session.</param> /// <param name="when">Time code of post.</param> private static bool IsReadyToPost(HttpSessionStateBase session, string when) { if (session == null || string.IsNullOrWhiteSpace(when)) { return true; } if (session["Start"] == null) { session.Add("Start", HomeController.FindTime(when)); Console.WriteLine("Set -Start- to " + session["Start"].ToString()); } var start = (DateTime)session["Start"]; var wait = HomeController.Elapsed(start, when); var real = DateTime.Now - (DateTime)session["RealStart"]; return real >= wait; }