user2467899
user2467899

Reputation: 575

Uppercase is not respected in PHP/MySQL

I have a problem with PHP and MySQL:

An user with account:

username: StAr
password: 4LasK4

Can login with:

username: star
password: 4lask4

Uppercases are not respected.

What may be the problem?

Thanks

Upvotes: 0

Views: 311

Answers (3)

O. Jones
O. Jones

Reputation: 108651

Many MySQL installations have a default collation setting of utf8_general_ci. This makes these two operations yield precisely the same result.

 SELECT * from users WHERE name = 'StAr'
 SELECT * from users WHERE name = 'star'

You can try ALTERing the collation for your name column in your database. Or you can use a query like this:

     SELECT * from users WHERE name = 'StAr' COLLATE utf8_bin

This utf8_bin collation compares for precise equality. If you put the COLLATE in your query, however, you may disable the use of an index for the query and cause MySQL performance trouble.

Upvotes: 0

Joni
Joni

Reputation: 111249

The collation determines whether two strings are equal. You should change the collation for the username and password columns to case sensitive or binary. For example:

alter table TableName modify username varchar(xx) collate utf8_bin,
    modify password varchar(xx) collate utf8_bin;

Upvotes: 6

Ander2
Ander2

Reputation: 5658

Check out the column definition and make sure your collation is not case insensitive (ci). You can try with this:

alter table your_table modify username varchar(xx) collate utf8_bin

Upvotes: 2

Related Questions