You are comparing the password as follows:
x.Senha.Equals(senha, StringComparison.Ordinal)
According to the documentation the StringComparison.Ordinal
makes the case-sensitive comparison, ie considering uppercase and lowercase.
When you’re comparing the user, you’re doing so:
x.Login.Equals(login, StringComparison.OrdinalIgnoreCase)
I don’t know the necessity of using the OrdinalIgnoreCase
in your case. I always use the StringComparison.InvariantCultureIgnoreCase
to that end, in this way:
x.Login.Equals(login, StringComparison.InvariantCultureIgnoreCase)
If you can, it’s worth reading "Difference between Invariantculture and Oridinal string comparison".
The code you posted already does what you want. That evalua:
"login" == "Login" > true (é case-insensitive)
"senha" == "Senha" > false (é case-sensitive)
But AP asked how to differentiate between upper and lower case. The
StringComparison.InvariantCultureIgnoreCase
does not do otherwise?– vinibrsl
@vnbrs by what I understand is to ignore the case-sensitive, the above function does this, and the below does not ignore the case-sensitive.
– gato