Support for non-western char login and passwords

Because StringUtils.encodeBase64() only deal with “ISO-8859-1” charset, in order to use UTF-8 login name and passwords I have to do this ugly hack:

String encId = new String(chatId.getBytes(“utf-8”), “ISO8859-1”);

String encPassword = new String(password.getBytes(“utf-8”), “ISO8859-1”);

conn.login(encId, encPassword);

It works but it would be nice the login() method supports UTF-8 natively.

Hi,

for me this seems to be another problem. Maybe something went wrong during registration of your username and password - there are known issues with Openfire and Smack.

Java stores a String always as USC-16, so 2 bytes are use.

A simple example which shows the problem which you may have encountered:

String chatId = "€";     /* chatId uses two bytes, no matter which content it has */
byte[] b = chatId.getBytes("utf-8"); /* b is three bytes, could be 1 to 4 bytes depending on the content of chatId */
String encId = new String(b, "ISO8859-1"); /* this will fail, '€' is not in ISO8859-1, java converts it to â?¬ - so it uses now six bytes */
System.out.println(chatId +"!="+ encId); /* print out both strings and wonder why they are not equal */

What you do with your code is what I have posted here, you modify your username or password in a rather ugly way and then it works. But that’s a very bad idea, one should find and fix the root cause for this problem.

LG

LG:

The user name and password are both Chinese and I registered them not using Smack but using the Adium IM client (similar to Gaim) running on Mac OS. Adium can log into this account fine (server is ejabberd). The problem is that Smack when login has to use BASE64 encoding to send the user name/password to server (following XMPP spec: http://xmpp.org/rfcs/rfc3920.html), and Smack always assume the user name String is ISO-8859 encoded while doing the string->byte conversion before the BASE64 (BASE64 takes a byte array as input). So my workaround is to transcode a string from UTF8 to iso8859 beforehand so the end BASE64 result generated by Smack is correct (when received by the server will correctly be decoded to the original UTF string). I guess since XMPP using XML for transport and XMLs are usually UTF-8 encoded, client/servers are expected to use UTF8?