public override async Task <bool> AddIncorrectPhaseTwoHashAsync( DbUserAccount userAccount, string phase2Hash, DateTime?whenSeenUtc = null, CancellationToken cancellationToken = default(CancellationToken)) { // Retrieve a reference to the table. CloudTable table = await GetTableAsync(TableName_RecentIncorrectPhase2Hashes, cancellationToken); TableOperation retriveOperation = TableOperation.Retrieve <IncorrectPhaseTwoHashEntity>(TableKeyEncoding.Encode(phase2Hash), TableKeyEncoding.Encode(userAccount.UsernameOrAccountId)); TableResult retrievedResult = await table.ExecuteAsync(retriveOperation, getTableRequestOptions(200), getOperationContext(), cancellationToken); if (retrievedResult.Result != null) { return(true); } // Write the hash to azure tables in the background. TaskHelper.RunInBackground( table.ExecuteAsync( TableOperation.InsertOrReplace(new IncorrectPhaseTwoHashEntity(userAccount.UsernameOrAccountId, phase2Hash, whenSeenUtc)), getTableRequestOptions(), getOperationContext(), cancellationToken) ); return(false); }
public override async Task <bool> HasClientWithThisHashedCookieSuccessfullyLoggedInBeforeAsync( DbUserAccount userAccount, string hashOfCookie, CancellationToken cancellationToken = default(CancellationToken)) { // Retrieve a reference to the table. CloudTable table = await GetTableAsync(TableName_SuccessfulLoginCookie, cancellationToken); //TableQuery<IncorrectPhaseTwoHashEntity> query = new TableQuery<IncorrectPhaseTwoHashEntity>().Where(TableQuery.CombineFilters( // TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, TableKeyEncoding.Encode(hashOfCookie)), // TableOperators.And, // TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, TableKeyEncoding.Encode(UsernameOrAccountId)))); var query = (from e in table.CreateQuery <SuccessfulLoginCookieEntity>() where e.PartitionKey == TableKeyEncoding.Encode(hashOfCookie) && e.RowKey == TableKeyEncoding.Encode(userAccount.UsernameOrAccountId) select e).AsTableQuery(); int count = 0; TableContinuationToken continuationToken = null; do { var partialResult = await query.ExecuteSegmentedAsync(continuationToken, cancellationToken); count += partialResult.Results.Count; continuationToken = partialResult.ContinuationToken; } while (continuationToken != null); return(count > 0); }
public override async Task <bool> HasClientWithThisHashedCookieSuccessfullyLoggedInBeforeAsync( DbUserAccount userAccount, string hashOfCookie, CancellationToken cancellationToken = default(CancellationToken)) { // Retrieve a reference to the table. CloudTable table = await GetTableAsync(TableName_SuccessfulLoginCookie, cancellationToken); TableOperation retriveOperation = TableOperation.Retrieve <SuccessfulLoginCookieEntity>(TableKeyEncoding.Encode(hashOfCookie), TableKeyEncoding.Encode(userAccount.UsernameOrAccountId)); TableResult retrievedResult = await table.ExecuteAsync(retriveOperation, getTableRequestOptions(200), getOperationContext(), cancellationToken); return(retrievedResult.Result != null); }
public override async Task <bool> AddIncorrectPhaseTwoHashAsync( DbUserAccount userAccount, string phase2Hash, DateTime?whenSeenUtc = null, CancellationToken cancellationToken = default(CancellationToken)) { // Retrieve a reference to the table. CloudTable table = await GetTableAsync(TableName_RecentIncorrectPhase2Hashes, cancellationToken); //TableQuery<IncorrectPhaseTwoHashEntity> query = new TableQuery<IncorrectPhaseTwoHashEntity>().Where(TableQuery.CombineFilters( // TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, TableKeyEncoding.Encode(phase2Hash)), // TableOperators.And, // TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, TableKeyEncoding.Encode(UsernameOrAccountId)) )); var query = (from e in table.CreateQuery <IncorrectPhaseTwoHashEntity>() where e.PartitionKey == TableKeyEncoding.Encode(phase2Hash) && e.RowKey == TableKeyEncoding.Encode(userAccount.UsernameOrAccountId) select e).AsTableQuery(); int count = 0; TableContinuationToken continuationToken = null; do { var partialResult = await query.ExecuteSegmentedAsync(continuationToken, cancellationToken); count += partialResult.Results.Count; continuationToken = partialResult.ContinuationToken; } while (continuationToken != null); if (count > 0) { // This phase2 hash already exists. return(true); } // Write the hash to azure tables in the background. TaskHelper.RunInBackground( table.ExecuteAsync( TableOperation.InsertOrReplace(new IncorrectPhaseTwoHashEntity(userAccount.UsernameOrAccountId, phase2Hash, whenSeenUtc)), cancellationToken) ); return(false); }
public SuccessfulLoginCookieEntity(string usernameOrAccountId, string hashOfCookie, DateTime?lastSeenUtc = null) { PartitionKey = TableKeyEncoding.Encode(hashOfCookie); RowKey = TableKeyEncoding.Encode(usernameOrAccountId); LastSeenUtc = lastSeenUtc ?? DateTime.UtcNow; }
public IncorrectPhaseTwoHashEntity(string usernameOrAccountId, string hashValue, DateTime?lastSeenUtc = null) { PartitionKey = TableKeyEncoding.Encode(hashValue); RowKey = TableKeyEncoding.Encode(usernameOrAccountId); LastSeenUtc = lastSeenUtc ?? DateTime.UtcNow; }