0

Why my login code not case sensitive?, How can I do?

My table "member"

 _________________________
|__username__|__password__| 
|____mango___|___123456___|

I try to login with

1. username = mango and password = 123456 , it's echo "true"
2. username = MANGO and password = 123456 , it's echo "true"
3. username = Mango and password = 123456 , it's echo "true"

Why my login code not case sensitive ?, how can i do ?

<?PHP
    include("connect.php");
    $strUsername = trim($_POST["usename"]);
    $strPassword = trim($_POST["password"]);

    $sql = "SELECT * FROM member WHERE username = '".mysql_real_escape_string($strUsername)."' 
            and password = '".mysql_real_escape_string($strPassword)."' ";
    $result=mysql_query($sql);
    $row=mysql_fetch_array($result);
    $count=mysql_num_rows($result);
    if($count==1)
       {
           echo "true";
       }  
    else
       {
           echo "false";
       }        
?>
Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
user3215821
  • 263
  • 2
  • 4
  • 11
  • 4
    A little-searching should have brought [this](http://stackoverflow.com/a/7857705/2513523) up – AyB Jan 27 '14 at 09:55
  • 1
    You are using [an unsuitable hashing algorithm](http://php.net/manual/en/faq.passwords.php) (i.e. none!) and need to [take better care](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) of your users' passwords. – Quentin Jan 27 '14 at 09:57
  • key success is `BINARY` ? – user3215821 Jan 27 '14 at 09:58

1 Answers1

1

Use binary:

$sql = "SELECT * FROM `member` WHERE BINARY `username` = '".mysql_real_escape_string($strUsername)."' 
        AND BINARY `password` = '".mysql_real_escape_string($strPassword)."' ";

There are also a few other improvements you could make to your code.

  1. You aren't using any hashing for your password - read this
  2. You are using deprecated mysql_* functions which PHP are trying to phase out. There are good alternatives out there, this article gives a good explanation which should help you choose which alternative would be best for you.
Nick
  • 6,316
  • 2
  • 29
  • 47