Bug #28166 Authentication failure with non-latin1 user names and mysql cmd line
Submitted: 30 Apr 2007 17:55 Modified: 30 Apr 2007 18:32
Reporter: Andrey Hristov Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0, probably 5.1 too OS:Any
Assigned to: CPU Architecture:Any

[30 Apr 2007 17:55] Andrey Hristov
Description:
During the authentication the server REENCODES with username sent from the server. Ergo, if the user is already sent as utf8 the utf8 is reencoded and thus the user can't log in?

The offending lines are (sql_parse.cc):
1034   user_buff[user_len= copy_and_convert(user_buff, sizeof(user_buff)-1,
1035                                        system_charset_info, user, user_len,
1036                                        thd->charset(), &dummy_errors)]= '\0';

Here is an example how to do it, I will attach it as a file too:

How to repeat:
<?php
var_dump(mysqli_connect("127.0.0.1", "ändräy", "bar", "test"));
?>

You can use a protocol dumper like wireshark to dump what is sent :
0000   00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00  ..............E.
0010   00 7b fe 46 40 00 40 06 3e 34 7f 00 00 01 7f 00  .{.F@.@.>4......
0020   00 01 80 ac 0c ea 16 1e bd 1c 16 30 03 bd 80 18  ...........0....
0030   01 01 fe 6f 00 00 01 01 08 0a 00 41 45 e6 00 41  ...o.......AE..A
0040   45 e6 43 00 00 01 8d a2 03 00 00 00 00 c0 08 00  E.C.............
0050   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
0060   00 00 00 00 00 00 c3 a4 6e 64 72 c3 a4 79 00 14  ........ndr..y..
0070   21 73 a7 80 34 e3 65 34 79 b4 69 06 c6 fe 92 80  !s..4.e4y.i.....
0080   40 fc c2 01 74 65 73 74 00                       @...test.

The result after reencoding :
0xc3 0x83 0xc2 0xa4 n d r 0xc3 0x83 0xc2 0xa4 y
compared to 
c3 a4 n d r c3 a4 y
[30 Apr 2007 17:55] Andrey Hristov
bug28166 test case

Attachment: a.php (application/x-php, text), 90 bytes.

[30 Apr 2007 18:32] Andrey Hristov
So, actually not a server issue but client issue. During the authentication handshake the client library should send the charset number along with the user name and password. It was sending latin1. mysqli fixed.