Search code examples
mysqlselectwhere-clauseuppercaselowercase

How to select exactly Username and password paying attention uppercase and lowercase letters - mysql


In this case i've created "logins" table:

+--------+--------------+---------+-----+
|ID_LOGIN| USERNAME     | PASSWORD      |
+--------+--------------+---------+-----+
| 1      | admin        | admin         | 
+--------+--------------+---------------+
| 2      | MaxiKIng1991 | #MaxiKIng1991$|
+--------+--------------+---------------+

I'm going to select all where username and password is specified. But i'd like pay attention to uppercase and lowercase letters. So please take a look. First i selected first login (username and password).

SELECT * FROM `logins` WHERE USERNAME = "AdMin" AND PASSWORD = "AdMin";

When i wrote this query it shows like this:

+--------+--------------+---------+-----+
|ID_LOGIN| USERNAME     | PASSWORD      |
+--------+--------------+---------+-----+
| 1      | admin        | admin         | 
+--------+--------------+---------------+

But in my opinion it shouldn't show the result. I noticed that sql query checks how many strings are in every column name. When i 1 letter too much or too less then shows nothing.

In that second query case:

SELECT * FROM `logins` WHERE USERNAME = "Maxiking1991" AND PASSWORD = "#maxiking1991$";

Then show below result:

+--------+--------------+---------+-----+
|ID_LOGIN| USERNAME     | PASSWORD      |
+--------+--------------+---------+-----+
| 2      |MaxiKIng1991  |#MaxiKIng1991$ | 
+--------+--------------+---------------+

But it shouldn't show that too.

Is that possible to pay attention to lowercase and uppercase letters in values in that mysql queries? any ideas? I have difficulty to search any solution on it. Thx for any help and advice.


Solution

  • Use This Case Sensitive Query like this

    select * from logins where BINARY USERNAME='admin';
    

    If you used 'Admin' instead of 'admin'.It will not match and it produce empty set.