Candor.Security.AzureStorageProvider.UserProvider.GetRecentFailedUserNameAuthenticationCount C# (CSharp) Method

GetRecentFailedUserNameAuthenticationCount() protected method

Gets the number of times a user name has failed authentication within the configured allowable failure period.
protected GetRecentFailedUserNameAuthenticationCount ( string name ) : int
name string
return int
        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();
        }