I have a simple DbContext with a Set<> of users.
I've got an ASP.NET Core Web API with authentication.
public User Authenticate(string username, string password)
{
var user = _ctx.Users.FirstOrDefault(x =>
x.Username.Equals(username, StringComparison.OrdinalIgnoreCase) &&
x.Password.Equals(password, StringComparison.OrdinalIgnoreCase));
bool exists = _ctx.Users.Any(x =>
x.Username.Equals(username, StringComparison.OrdinalIgnoreCase) &&
x.Password.Equals(password, StringComparison.OrdinalIgnoreCase));
bool usernameCorrect = _ctx.Users.First().Username.Equals(username, StringComparison.OrdinalIgnoreCase);
bool passwordCorrect = _ctx.Users.First().Password.Equals(password, StringComparison.OrdinalIgnoreCase);
if (user == null)
{
return null;
}
[...]
}
The problem is that _ctx.Users.FirstOrDefaultis returning null.
You might think this is simple: "the condition does not match"
But:
What is going on here?
