View Full Version : login username issue

06-18-2010, 02:02 AM
If a username registers, their username's first letter is automatically capitalized and sent to the database. If a user decides to capitalize a second letter in the middle of their username (Ex: McLoven), unless the username is typed with that capitalized letter, I get an error that says "Incorrect Password!". The password is set as an MD5 encryption.

Any suggestions on what to do to fix this problem?

MySql version: 5.0.91

Here's my Login.php

$username = ucfirst($_POST['username']);
$password = $_POST['password'];

if ($username&&$password)

$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'];
$userid = $row['id'];

// $_SESSION['username'] = $username;
// $_SESSION['userid'] = $userid;

// check to see if they match
if ($username==$dbusername&&md5($password)==$dbpassword)
//echo "You're In! <a href='member.php'>Click</a> here to enter the member page.";
$_SESSION['views'] = 0;
echo "Incorrect Password!";

die("That user doesn't exist!");

die("Please fill out all fields!");


06-18-2010, 02:25 AM
You let them enter it any way they want (any combination of caps and small),
and then you make the whole thing lowercase before you save it.

$username = strtolower($_POST['username']);

If it's important to let them specify caps and small, then save it BOTH ways,
as two usernames. Always use the lowercase for login, but show them the
other one if they need to see it with mixed small and caps.

06-18-2010, 02:35 AM
Incorect password error can only be true if your query returns at least 1 result. Unless you collate your query, declare a binary derived type, or declare it as case sensitive, mysql will search insensitively.

06-19-2010, 06:00 AM
Let them enter their user name any way they want. Don't try to force anything to something they didn't type. The prompt should let them know their user name is case sensitive.

If you *must* play with their entry then just force everything to all lowercase but keep that info to yourself. They don't need to know that.