Regarding DERBY-5538 <https://issues.apache.org/jira/browse/DERBY-5538>,
I did some changes regarding this issue and I made some updates. Here I
attached diff file and can you please check on this.



-- 
*K. A. Dinuka Nadeeshan*
Undergraduate of Dept. of Computer Engineering, Faculty of Engineering,
University of Peradeniya, Sri-Lanka
LinkedIn:* https://www.linkedin.com/in/dinuka-nadeeshan/
<https://www.linkedin.com/in/dinuka-nadeeshan/>*
GitHub: *https://github.com/dinukanadeeshan
<https://github.com/dinukanadeeshan>*
Index: 
java/engine/org/apache/derby/impl/jdbc/authentication/AuthenticationServiceBase.java
===================================================================
--- 
java/engine/org/apache/derby/impl/jdbc/authentication/AuthenticationServiceBase.java
        (revision 1810047)
+++ 
java/engine/org/apache/derby/impl/jdbc/authentication/AuthenticationServiceBase.java
        (working copy)
@@ -409,7 +409,8 @@
             String userName =
                     key.substring(Property.USER_PROPERTY_PREFIX.length());
             userPassword =
-                    encryptUsingDefaultAlgorithm(userName, userPassword, p);
+                       //encryptUsingDefaultAlgorithm(userName, userPassword, 
p);
+                                               
encryptUsingDefaultAlgorithm(userName, userPassword.toCharArray(), p);
                }
 
                return userPassword;
@@ -452,9 +453,9 @@
         * @return encrypted user password (digest) as a String object
      *         or {@code null} if the plaintext password is {@code null}
         */
-       protected String encryptPasswordSHA1Scheme(String plainTxtUserPassword)
+       protected String encryptPasswordSHA1Scheme(char[] plainTxtUserPassword)
        {
-               if (plainTxtUserPassword == null)
+               if (plainTxtUserPassword == null || plainTxtUserPassword.length 
== 0)
                        return null;
 
                MessageDigest algorithm = null;
@@ -503,13 +504,13 @@
      * @param str string
      * @return the byte[] (with hexadecimal format) form of the string (str)
      */
-    private static byte[] toHexByte(String str)
+    private static byte[] toHexByte(char[] str)
     {
-        byte[] data = new byte[str.length() * 2];
+        byte[] data = new byte[str.length * 2];
 
-        for (int i = 0; i < str.length(); i++)
+        for (int i = 0; i < str.length; i++)
         {
-            char ch = str.charAt(i);
+            char ch = str[i];
             int high_nibble = (ch & 0xf0) >>> 4;
             int low_nibble = (ch & 0x0f);
             data[i] = (byte)high_nibble;
@@ -537,10 +538,10 @@
      * @throws StandardException if the specified algorithm is not supported
      */
     String encryptPasswordConfigurableScheme(
-            String user, String password, String algorithm)
+            String user, char[] password, String algorithm)
             throws StandardException
     {
-        if (password == null) {
+        if (password == null || password.length == 0) {
             return null;
         }
 
@@ -556,7 +557,7 @@
 
         try {
             md.update(user.getBytes(ENCODING));
-            md.update(password.getBytes(ENCODING));
+            md.update(password.toString().getBytes(ENCODING));
         } catch (UnsupportedEncodingException uee) {
             // UTF-8 should always be available, so this should never happen.
             throw StandardException.plainWrapException(uee);
@@ -593,7 +594,7 @@
      * @throws StandardException if the specified algorithm is not supported
      */
     private String encryptUsingDefaultAlgorithm(String user,
-                                                String password,
+                                                char[] password,
                                                 Dictionary props)
             throws StandardException {
 
@@ -676,9 +677,9 @@
      *
         * @return a substituted password.
      */
-    protected String substitutePassword(
+    protected char[] substitutePassword(
                 String userName,
-                String password,
+                char[] password,
                 Properties info,
                 boolean databaseUser) {
 
@@ -711,7 +712,7 @@
         messageDigest.reset();
 
         byte[] bytePasswd = null;
-        byte[] userBytes = toHexByte(userName);
+        byte[] userBytes = toHexByte(userName.toCharArray());
 
         if (SanityManager.DEBUG)
         {
@@ -731,7 +732,7 @@
         byte[] targetSeed_ =
             StringUtil.fromHexString(targetSeedstr, 0, targetSeedstr.length());
 
-        String hexString = null;
+        char[] hexString = null;
         // If user is at the database level, we don't encrypt the password
         // as it is already encrypted (BUILTIN scheme) - we only do the
         // BUILTIN encryption if the user is defined at the system level
@@ -742,8 +743,8 @@
             bytePasswd = toHexByte(password);
             messageDigest.update(bytePasswd);
             byte[] encryptVal = messageDigest.digest();
-            hexString = ID_PATTERN_SHA1_SCHEME +
-                StringUtil.toHexString(encryptVal, 0, encryptVal.length);
+            hexString = (ID_PATTERN_SHA1_SCHEME +
+                StringUtil.toHexString(encryptVal, 0, 
encryptVal.length)).toCharArray();
         }
         else
         {
@@ -775,6 +776,6 @@
         passwordSubstitute = messageDigest.digest();
 
         return StringUtil.toHexString(passwordSubstitute, 0,
-                                      passwordSubstitute.length);
+                                      passwordSubstitute.length).toCharArray();
     }
 }

Reply via email to