Database user backend improvements

Adds a field `uid_lower` to the database (filled during upgrade) as a way to prevent having to use LOWER() in the sql and make proper use of indexes.

Also some generic cleanup for the backend.

cc @karlitschek @DeepDiver1975 @dragotin @tanghus