U E D R , A S I H C RSS

MySQL/Password Function In Java


// JDK 1.5 ~]~C~A~W~P~D~\ ~O~Y~^~Q. (String.format ~U~H~X ~U~L문~W~P)

package cau.util;

public class MySqlUtil {
        public static String toMySQLPassword(String aStr) {
                   int nr = 1345345333;
           int add = 7;
           int nr2 = 0x12345671;

           int size = aStr.length();
           for(int i=0;i<size;i++)
           {
                  if(aStr.charAt(i) == ' ' || aStr.charAt(i) == '\t') continue;  /* skipp space in password */
                  int tmp = (aStr.charAt(i));
                  nr ^= (((nr & 63)+ add)* tmp) + (nr << 8);
                  nr2 += (nr2 << 8) ^ nr;
                  add += tmp;
           }
        int result1=nr & ((1 << 31) -1); /* Don't use sign bit (str2int) */
        int result2=nr2 & ((1 << 31) -1);
        String result = String.format("%08x%08x",new Object[]{new Integer(result1),new Integer(result2)});
        return result;

        }

        public static void main(String[] args) {
                System.out.println(MySqlUtil.toMySQLPassword("hahaha"));
                System.out.println(MySqlUtil.toMySQLPassword("testing"));
                System.out.println(MySqlUtil.toMySQLPassword("abcd1234"));
        }
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:50
Processing time 0.0180 sec