/// <summary> /// Inserts a new user authentication history. /// </summary> /// <param name="history"></param> protected override void InsertUserHistory(AuthenticationHistory history) { TableProxyAuthenticationHistoryByUserName.Insert(history); if (history.UserSession != null && !history.UserSession.RenewalToken.Equals(Guid.Empty)) { TableProxyAuthenticationHistoryByToken.InsertOrUpdate(history); } }
/// <summary> /// Gets the number of times a user name has failed authentication within the configured allowable failure period. /// </summary> /// <param name="name"></param> /// <returns></returns> protected override int GetRecentFailedUserNameAuthenticationCount(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("name", "User name must be supplied."); } var rkCompare = DateTime.MaxValue.Ticks - DateTime.UtcNow.AddMinutes(-1 * FailurePeriodMinutes).Ticks; var rowKeyFilter = TableQuery.GenerateFilterCondition(TableConstants.RowKey, QueryComparisons.LessThanOrEqual, //smallest is latest rkCompare.ToString("d19")); var attempts = TableProxyAuthenticationHistoryByUserName.QueryPartition(String.Format("UserName|{0}", name.ToLower()).GetValidPartitionKey(), rowKeyFilter, take: AllowedFailuresPerPeriod * 2); if (attempts == null || attempts.Count == 0) { return(0); } //already sorted descending return(attempts.TakeWhile(t => !t.Entity.IsAuthenticated).Count()); }