Because of the way our databases are collated they ignore case for usernames and passwords, which we're currently unable to fix at the database level. It appears from this thread that WHERE BINARY 'something' = 'Something'
should fix the problem, but I haven't been able to figure out to get Django to insert BINARY
. Any tips?
Asked
Active
Viewed 1,546 times
0
-
Just as a side note, you shouldn't store passwords in your database without running them through `sha1` or some other hashing function. – Kaivosukeltaja May 29 '12 at 15:49
-
Good point, but we still need case sensitivity for usernames. – exupero May 29 '12 at 17:24
-
possible duplicate of [Can you achieve a case insensitive 'unique' constraint in Sqlite3 (with Django)?](http://stackoverflow.com/questions/276656/can-you-achieve-a-case-insensitive-unique-constraint-in-sqlite3-with-django) – CharlesB May 30 '12 at 08:47
1 Answers
1
I don't think there's an easy way to force Django to add something into a query content.
You may want to simply write a raw SQL query within the Django to get objects filtered with case-sensitive comparison and then use them in normal queries.
The other approach is to use Django case-sensitive filters in order to achieve the same result. E.g. contains
/startswith
both use BINARY LIKE
and may be used while comparing two strings with the same length (like a password hash)). Finally, you can use regexp
to do the case-sensitive comparison. But these are rather ugly methods in that situation. They have an uncessary overhead and you should avoid them as long as it's possible.

Wojciech Żółtak
- 950
- 6
- 16