I'm storing usernames in my database but wish to retain the username casing so that users can have usernames such as "FooBAR".
I also wish for usernames to be unique (regardless of case) - "BaR" would cause "bar" to be unavailable.
I see three ways of doing this:
Firstly, I could query my Users table like so:
bool usernameAvailable = !_context.Users.Any(u => String.Equals(u.Username, username, StringComparison.OrdinalIgnoreCase));
Secondly, I could convert both usernames to upper or lower like so:
username = username.ToUpper();
bool usernameAvailable = !_context.Users.Any(u => u.Username.ToUpper() == username);
Thirdly, I could create a second column in my table that stores the upper/lowercase version of the username:
username = username.ToUpper();
bool usernameAvailable = !_context.Users.Any(u => u.UsernameUpper == username);
This would require more space in the database but would be the easiest to query.
Any insight would be appreciated.
This has almost certainly been answered previously, so please point me in the direction of any previous posts as i'm unable to find what i'm looking for.