Java Hash String hashPassword(String password)

Here you can find the source of hashPassword(String password)

Description

Generate binary hash from raw text string Used for Pre-4.1 password handling

License

Open Source License

Parameter

Parameter Description
password IN plain text password to build hash

Return

OUT store hash in this location

Declaration




public static long[] hashPassword(String password) 

Method Source Code

//package com.java2s;
/*/*  w  ww  .  java2s .  c  o  m*/
 * Copyright (c) 2013, OpenCloudDB/MyCAT and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software;Designed and Developed mainly by many Chinese 
 * opensource volunteers. you can redistribute it and/or modify it under the 
 * terms of the GNU General Public License version 2 only, as published by the
 * Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * Any questions about this component can be directed to it's project Web address 
 * https://code.google.com/p/opencloudb/.
 *
 */

public class Main {
    /**
     * Generate binary hash from raw text string
     * Used for Pre-4.1 password handling
     * <p/>
     *
     * @param password IN  plain text password to build hash
     * @return OUT store hash in this location
     */

    //    password_len IN  password length (password may be not null-terminated)
    //    private static long[] hashPassword(String password, int passwordLen)
    public static long[] hashPassword(String password) {
        long nr = 1345345333L;
        long add = 7;
        long nr2 = 0x12345671L;
        long tmp;
        for (int i = 0; i < password.length(); ++i) {
            switch (password.charAt(i)) {
            case ' ':
            case '\t':
                continue;
            default:
                tmp = (0xff & password.charAt(i));
                nr ^= ((((nr & 63) + add) * tmp) + (nr << 8));
                nr2 += ((nr2 << 8) ^ nr);
                add += tmp;
            }
        }
        long[] result = new long[2];
        result[0] = nr & 0x7fffffffL;
        result[1] = nr2 & 0x7fffffffL;
        return result;
    }
}

Related

  1. hasHint(String hint, String parameter)
  2. hashIt(String s)
  3. hasHost(String path)
  4. hashOTP(String otp)
  5. hashPassword(String password)
  6. hashSpriteName(String name)
  7. hashString(CharSequence str)
  8. hashString(String data, int seed)
  9. hashString(String s)