Form Based Authentication fails with unicode characters
I have implemented form based authentication using Tomcat 6 and MySQL 5.0. It works just fine for user names and passwords that use English characters. But, if I try to use Korean, Japanese, or other Unicode characters, then the login always fails.
How can I make form based authentication work for Unicode?
I figured it out. Finally.
I made two changes in my configuration files. I'm not entirely sure which one fixed it or if they are both necessary. But just for your information, here are the two changes.
1. Since I am using MySQL as the user database, the Realm's connection URL to the database needed to have the encoding information. Here is what I now have in my context.xml file:
<Realm connectionName="myConnectionName" connectionPassword="***"
roleNameCol="Role" userCredCol="Password" userNameCol="UserName" userRoleTable="Users"
userTable="Users" className="org.apache.catalina.realm.JDBCRealm" digest="SHA" digestEncoding="utf-8" />
2. I also added the following tag to the context.xml file. It explicitly tells Tomcat's FormAuthenticator to use utf-8 encoding:
<Valve className="org.apache.catalina.authenticator.FormAuthenticator" characterEncoding="utf-8" />
And as a final note, I made these changes and restarted my Tomcat, but it still did not work until I came back to work the next day. (And, yes, I did indeed spend several hours searching for answers. I found nothing and went home frustrated.) Therefore, if it is not working for you, you may want to reboot the computer just to make sure...
I hope that this post will help someone.