Shibbir
Shibbir

Reputation: 91

Case-Sensitive Queries

I can get user inputed name(username) with following code from a form. So my question is if i put Shibbirbd (First letter is Capital but it's shibbirbd in my database) then it's successfully go to user login panel! But it's wrong. why this happened? Mysql Database username is: shibbirbd.

Login form script:

$uname = mysql_real_escape_string(htmlspecialchars(trim($_POST['uname'])));
$pass = mysql_real_escape_string(htmlspecialchars(trim($_POST['pass'])));

Upvotes: 2

Views: 91

Answers (5)

4b0
4b0

Reputation: 22323

Use COLLATE for case-sensitive.You see example in this link.
http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html

Upvotes: 0

Sp4cecat
Sp4cecat

Reputation: 991

Sounds like the column collation is case-insensitive, which is the default. Try changing it to a case-sensitive collation, for example latine_general_cs

Upvotes: 0

Sampson
Sampson

Reputation: 268444

You can change your WHEREclause to WHERE BINARY (WHERE BINARY uname = '$uname') to test the binary value of the usernames against one another for equality.

If you would like all queries on this table to be case-sensitive, you should consider changing the collation, as @Kolink suggested.

Upvotes: 2

rekire
rekire

Reputation: 47975

In most cases the the strings are non casesensitive compaired. Why is it important that the username is casesensitive?

In MySQL you can see that with the encoding _ci which meanes case insensetive. Try some _bin or _cs formates if you want.

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324790

Are you saying that you're expecting it to not log you in if you have uppercase letters where there should be lowercase?

In that case, change the collation of the table to something that's case-sensitive, such as utf8_bin.

Upvotes: 1

Related Questions