diff -rub postgresql-jdbc-8.2-506.src/build.xml src/build.xml
--- postgresql-jdbc-8.2-506.src/build.xml	2007-04-24 21:19:07.000000000 +0300
+++ src/build.xml	2007-11-28 19:57:59.000000000 +0200
@@ -138,7 +138,7 @@
  
        <!-- jdbc3 subpackage -->
        <include name="${package}/jdbc3/Abstract*.java" if="jdbc3plus" />
-       <include name="${package}/jdbc3/PSQLSavepoint.java" if="jdbcplus" />
+       <include name="${package}/jdbc3/PSQLSavepoint.java" if="jdbc3plus" />
 
        <include name="${package}/jdbc3/Jdbc3Array.java" if="jdbc3"/>
        <include name="${package}/jdbc3/Jdbc3Blob.java" if="jdbc3"/>
diff -rub postgresql-jdbc-8.2-506.src/org/postgresql/core/Encoding.java src/org/postgresql/core/Encoding.java
--- postgresql-jdbc-8.2-506.src/org/postgresql/core/Encoding.java	2006-10-30 20:30:16.000000000 +0200
+++ src/org/postgresql/core/Encoding.java	2007-11-28 19:24:53.000000000 +0200
@@ -23,7 +23,27 @@
  */
 public class Encoding
 {
-    private static final Encoding DEFAULT_ENCODING = new Encoding(null);
+	/**
+	 * The charset used for encoding user name, database name and password during the authentication phase
+	 * of a connection (before things like encoding can be "discussed" with the server).  
+	 */
+	public static final String AUTHENTICATION_PHASE_ENCODING;
+	static
+	{
+		// beginning with version 1.5 there's a method in Charset that gives the platform encoding 
+		String platformEncoding = null;
+		try
+		{
+			platformEncoding = System.getProperty("file.encoding");
+		}
+		catch (Exception e)
+		{}
+		if (isAsciiExtension(platformEncoding))
+			AUTHENTICATION_PHASE_ENCODING = platformEncoding;
+		else AUTHENTICATION_PHASE_ENCODING = "UTF-8";  // this is guaranteed to be supported and is also an ASCII extension
+	}
+	
+	private static final Encoding DEFAULT_ENCODING = new Encoding(AUTHENTICATION_PHASE_ENCODING);
 
     /*
      * Preferred JVM encodings for backend encodings.
@@ -245,6 +265,40 @@
     }
 
     /**
+     * Tells wheter the submitted JVM encoding is known to be an ASCII extension.
+     * An encoding is an ASCII extension if any string of valid ASCII characters is a valid string with the same
+     * binary representation in this encoding as well.
+     * @param encodingName the JVM charset name
+     * @return <code>true</code> when the supplied charset is known to be an ASCII extension; a <code>false</code>
+     * does not necessarily imply that the supplied charset is not an ASCII extension, but merely that the fact is not known. 
+     */
+    public static boolean isAsciiExtension(String encodingName)
+    {
+    	if (encodingName == null)
+    		return false;
+    	
+    	// bring all letters to lower case and eliminate delimiters (see the legal charset names in java.nio.charset.Charset)
+    	StringBuffer enc = new StringBuffer(encodingName.toLowerCase());
+    	int i = 0;
+    	char c;
+    	while (i < enc.length())
+    	{
+    		c = enc.charAt(i);
+    		if (c == '-' || c == '.' || c == ':' || c == '_')
+    			enc.deleteCharAt(i);
+    		else i++;
+    	}
+    	encodingName = enc.toString();  
+    	if (encodingName.startsWith("latin")
+    			|| encodingName.startsWith("iso8859")
+    			|| encodingName.startsWith("cp125")
+    			|| encodingName.startsWith("windows125")
+    			|| encodingName.startsWith("utf8"))  // others may exist, please add if so...
+    		return true;
+        return false;
+    }
+
+    /**
      * Test if an encoding is available in the JVM.
      *
      * @param encodingName the JVM encoding name to test
diff -rub postgresql-jdbc-8.2-506.src/org/postgresql/core/PGStream.java src/org/postgresql/core/PGStream.java
--- postgresql-jdbc-8.2-506.src/org/postgresql/core/PGStream.java	2006-10-30 20:30:16.000000000 +0200
+++ src/org/postgresql/core/PGStream.java	2007-11-28 19:24:53.000000000 +0200
@@ -57,7 +57,7 @@
         this.port = port;
 
         changeSocket(new Socket(host, port));
-        setEncoding(Encoding.getJVMEncoding("US-ASCII"));
+        setEncoding(Encoding.defaultEncoding());
     }
 
     public String getHost() {
diff -rub postgresql-jdbc-8.2-506.src/org/postgresql/core/v3/ConnectionFactoryImpl.java src/org/postgresql/core/v3/ConnectionFactoryImpl.java
--- postgresql-jdbc-8.2-506.src/org/postgresql/core/v3/ConnectionFactoryImpl.java	2006-12-01 10:53:45.000000000 +0200
+++ src/org/postgresql/core/v3/ConnectionFactoryImpl.java	2007-11-28 19:24:53.000000000 +0200
@@ -220,8 +220,8 @@
         byte[][] encodedParams = new byte[params.length * 2][];
         for (int i = 0; i < params.length; ++i)
         {
-            encodedParams[i*2] = params[i][0].getBytes("US-ASCII");
-            encodedParams[i*2 + 1] = params[i][1].getBytes("US-ASCII");
+            encodedParams[i*2] = params[i][0].getBytes(Encoding.AUTHENTICATION_PHASE_ENCODING);
+            encodedParams[i*2 + 1] = params[i][1].getBytes(Encoding.AUTHENTICATION_PHASE_ENCODING);
             length += encodedParams[i * 2].length + 1 + encodedParams[i * 2 + 1].length + 1;
         }
 
@@ -290,7 +290,7 @@
                         byte[] rst = new byte[2];
                         rst[0] = (byte)pgStream.ReceiveChar();
                         rst[1] = (byte)pgStream.ReceiveChar();
-                        String salt = new String(rst, 0, 2, "US-ASCII");
+                        String salt = new String(rst, 0, 2, Encoding.AUTHENTICATION_PHASE_ENCODING);
 
                         if (logger.logDebug())
                             logger.debug(" <=BE AuthenticationReqCrypt(salt='" + salt + "')");
@@ -299,7 +299,7 @@
                             throw new PSQLException(GT.tr("The server requested password-based authentication, but no password was provided."), PSQLState.CONNECTION_REJECTED);
 
                         String result = UnixCrypt.crypt(salt, password);
-                        byte[] encodedResult = result.getBytes("US-ASCII");
+                        byte[] encodedResult = result.getBytes(Encoding.AUTHENTICATION_PHASE_ENCODING);
 
                         if (logger.logDebug())
                             logger.debug(" FE=> Password(crypt='" + result + "')");
@@ -351,7 +351,7 @@
                         if (password == null)
                             throw new PSQLException(GT.tr("The server requested password-based authentication, but no password was provided."), PSQLState.CONNECTION_REJECTED);
 
-                        byte[] encodedPassword = password.getBytes("US-ASCII");
+                        byte[] encodedPassword = password.getBytes(Encoding.AUTHENTICATION_PHASE_ENCODING);
 
                         pgStream.SendChar('p');
                         pgStream.SendInteger4(4 + encodedPassword.length + 1);
diff -rub postgresql-jdbc-8.2-506.src/org/postgresql/util/MD5Digest.java src/org/postgresql/util/MD5Digest.java
--- postgresql-jdbc-8.2-506.src/org/postgresql/util/MD5Digest.java	2005-01-11 10:25:49.000000000 +0200
+++ src/org/postgresql/util/MD5Digest.java	2007-11-28 19:24:53.000000000 +0200
@@ -18,6 +18,8 @@
 
 import java.security.*;
 
+import org.postgresql.core.Encoding;
+
 public class MD5Digest
 {
     private MD5Digest()
@@ -45,8 +47,8 @@
         {
             md = MessageDigest.getInstance("MD5");
 
-            md.update(password.getBytes("US-ASCII"));
-            md.update(user.getBytes("US-ASCII"));
+            md.update(password.getBytes(Encoding.AUTHENTICATION_PHASE_ENCODING));
+            md.update(user.getBytes(Encoding.AUTHENTICATION_PHASE_ENCODING));
             temp_digest = md.digest();
 
             bytesToHex(temp_digest, hex_digest, 0);
