Jump to content

Recommended Posts

Hi, I'm making a login page and I want to allow users type in case-insensitive username and password.

I'm using utf8_general_ci collation.

Here's my PHP code.

 

$username= $_POST['username'];
$password = $_POST['password'];

if ($email&&$password){
$connect = mysql_connect("localhost","root","") or die("Couldn't connect to the database");
mysql_select_db("nemo") or die("Couldn't find the database.");
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
	{
	while ($row = mysql_fetch_assoc($query))
		{
			$dbusername= $row["username"];
			$dbpassword = $row["password"];
		}
	if ($username==$dbusername&&$password==$dbpassword)
		{
			echo "Logged in";
		}
		else
			echo "Wrong password."
	}
else
	die("Username not found.");
}
else
die("Enter your username and password.");

 

After doing some search, I found that collation ending with ci means case insensitive.

But I can't log in with ABC if the username in database is abc.

I know I can use strtolower to make everything to lower case but

I'm really curious why this happens.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/230077-login-case-sensitivity/
Share on other sites

Thanks for your reply.

 

I'm in a hurry to finish a site and I actually got that code from watching a Youtube PHP tutorial clip.

I thought that the code itself must be correct.

After struggling for a few hours, I've come up with this.

 

$query = mysql_query("SELECT * FROM users WHERE username='$username' and password='$password'");

 

It works as I wished and I hope this one is properly coded.

Please advise me if it's not.

 

Thank you!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.