public void TestComparer() { var equals = new ConstantTimeComparer("a"); foreach (var index in Enumerable.Range(0, 10)) { Assert.True(equals.CheckEquality("a")); Assert.False(equals.CheckEquality("b")); Assert.False(equals.CheckEquality("")); } }
public async Task Invoke(HttpContext context) { var passwordHeader = context.Request.Headers[PasswordHeaderKey]; var targetPassword = ""; if (passwordHeader.Count > 0) { targetPassword = passwordHeader[0]; } if (!comparer.CheckEquality(targetPassword)) { context.Response.StatusCode = StatusCodes.Status401Unauthorized; await context.Response.WriteAsync("Unauthorized."); return; } await this._next(context); }