Sync gateway user and password with Danish national characters

I have discovered that we have a problem that is related to using national Danish characters (æøåÆØÅ) in passwords.

We have an app-server where we control changes to users in the sync.gateway like creation/deletion and setting a password. I have one user that has not been able to connect to the sync.gateway and after a lot of trial/error I have found out that using one of the Danish letters in the password on the sync.gateway seems to cause a problem (not anywhere else in our application).

Is there any way I can allow this?

I have tried another special character like ! - and that works…

Sync Gateway doesn’t have any restriction around non-ASCII characters in passwords. I was able to create a user with password ‘æøåÆØÅ’ locally, and authenticate successfully as that user with that password (using basic auth).

From your description it sounds like the password might be getting modified at some point prior to reaching Sync Gateway - can you share some more details on the specific requests or operations that you’re using when you encounter the connection issue described?


I use this code (Java) to set the password/user in the sync gateway from my application :

registerUrl = "http://" + server + ":4985/" + DataBean.CB_DATA_STORE + "/_user/"
CHARSET_UTF8 = "utf-8"

Code to update user in sync. gateway:
url = new URL(registerUrl + key.toUpperCase());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json;charset=" + CHARSET_UTF8);
connection.setRequestProperty("charset", CHARSET_UTF8);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
String data = String.format(LOGIN_RECORD, key.toUpperCase(), email, password);

Anything in this that could spoil the password if it contains Danish letters??

That looks suspicious. DataOutput.writeBytes(String) only writes one byte of each character in the string.

Try replacing with wr.write(data.getBytes(UTF_8));

Or, since DataOutputStream isn’t doing anything useful here, write directly to the connection’s OutputStream:

OutputStream out = connection.getOutputStream()

key.toUpperCase() is also dodgy since it uses the default locale, but that seems less likely to be the source of the problem. Suggested replacement would be key.toUpperCase(Locale.ROOT)


1 Like

… of course!

Thanks for that! It works as expected. Not sure why the code was like it was - probably just found an example back when it was set up and adjusted that to work… :innocent: :joy:

1 Like