Login without differentiating between uppercase and lowercase letters?

0

I am making a login system. In the table is registered a user "UseR01" , when the client will log in if he put in the "user01" field I want you to validate anyway.

Here's the code I'm using.

$Name = mysqli_real_escape_string($conn, $_POST['Name']);
$Pass = mysqli_real_escape_string($conn, $_POST['Pass']);
$PassMD5 = md5($Pass);

$result1 = "SELECT * FROM users WHERE username = '$Name' && userpass = '$PassMD5' LIMIT 1";
$result2 = mysqli_query($conn, $result1);
$result3 = mysqli_fetch_assoc($result2);

if(isset($result3)){
    echo "SUCCESS";
}else{
    echo "FAIL";
}
    
asked by anonymous 18.08.2017 / 00:53

3 answers

1

The simplest way would be convert strings before the comparison:

$result1 = "SELECT * FROM users WHERE UPPER(username) = UPPER('$Name') && userpass = '$PassMD5' LIMIT 1";
    
18.08.2017 / 01:00
3
// Converta o nome de usuário em minúsculas
$username = strtolower($Name);

// Use LOWER () para converter o nome de usuário em minúsculas
$result1 = "SELECT * FROM users WHERE LOWER(username)='$username' && userpass = '$PassMD5' LIMIT 1";
    
18.08.2017 / 01:23
3

As you do not know how it's being stored, use the COLLATIONS CASE INSENSITIVE to do this job:

$sql = "SELECT * FROM users WHERE username COLLATE utf8_general_ci = '$Name' && userpass = '$PassMD5' LIMIT 1";

For accentuation, the latin1_general_ci is also used.

Here is the list of collations supported by MariaDB .

    
18.08.2017 / 02:51