Question:
How do I make inputs case-sensitive in PHP/MySQL?
anonymous
2008-01-05 03:26:25 UTC
I have a register script that adds the password to the database and as I've noticed, it doesn't matter if the password is PASSWORD or PaSsWoRd or password, they all work when logging in at the login page.

I want the password to be case-sensitive, so if the user set "Password", either "PASSWORD" or "PassWorD" shouldn't work. ONLY "Password" when they're logging in.

It's PHP and MySQL that I'm coding with.
Six answers:
Alan
2008-01-05 22:42:45 UTC
I'm guessing that in your mysql query you're checking the username and password (for example WHERE `username` = 'username' AND `password` = 'password'). Mysql checks fields case insensitively, what you can simply do is WHERE `username` = 'username' and then retrieve that row and check the stored username's password against the password they gave you since PHP string checks are case sensitive.



Also, like someone else said, make sure you encrypt your passwords into and out of the mysql table (for example encrypt it in with md5($storedPassword) and then check their inputted password with md5($givenPassword).
anonymous
2008-01-05 03:45:00 UTC
For a start you must be storing the passwords in clear text. This is very dangerous. If you store them in password() format, they are encrypted. You can then compare the encrypted version of password typed against the encrypted one. This should achieve case sensitivity.
anonymous
2008-01-05 03:33:26 UTC
it is by default case sensitive. So your mistake should be in the php script where you are cheking if the input password equals to the password in the database. So if you use '==' in the if statement you should not have any problems.



example: if ($password == $user[password]) {}
anonymous
2016-10-22 03:29:33 UTC
in accordance to RFC 821 (the SMTP protocol): "For some hosts the person call is case delicate, and SMTP implementations ought to take case to maintain the case of person names as they look in mailbox arguments." So the definitive answer is convinced.
seydok
2013-11-23 14:23:56 UTC
convert it to bin2hex it will work fine for yo.. let me know if it ok thks
gabba
2015-08-31 19:36:25 UTC
silverstar214


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...