开发者

Is it a good idea to Strtolower the username then store it in database?

In a php/mysql application where people can registre, is it a good idea to strtolower th开发者_如何转开发e username then store in the database in order to not have problems in the future? because people are using DiFfeReNt cases and i'm afraid that will make conflict in some queries.

Thanks


It really doesn't matter - MySQL is case insensitive unless you specify so Andy, andy and AnDy will all match.

The caveat is collation - however:

The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default.

Beware, if you are using latin1_general_cs the cs stands for case sensitive, and all your queries will be case sensitive! Here's some more info on charsets and collation.


If lowercasing usernames makes you avoid conflict in some queries (as you stated), then you have probably have some larger problems at hand.

You should be sanitizing all database input, but lowercasing usernames as such should not be necessary.


I would suggest to store it the way user entered it, especially if you display it somewhere.
But when user registers a new username and you don't want to allow such duplicates, then check without case sensitivity before saving.


No case issue can cause any conflict with the query.


No. You can leave your users disappointed if you change their username in any way. You can change the collation of the column on the DB to be case insensitive.


You should store it the way the user entered it.

What you MUST provide is a case insensitive authentication, when comparing just lower(user.input) with lower(database.data).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜