Java Hash String hashPassword(String password)

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

Description

hash Password

License

Apache License

Declaration

public static short hashPassword(String password) 

Method Source Code

//package com.java2s;
/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
    /*from  w w  w  . ja va2  s  .c o  m*/
   http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */

public class Main {
    public static short hashPassword(String password) {
        byte[] passwordCharacters = password.getBytes();
        int hash = 0;
        if (passwordCharacters.length > 0) {
            int charIndex = passwordCharacters.length;
            while (charIndex-- > 0) {
                hash = ((hash >> 14) & 0x01) | ((hash << 1) & 0x7fff);
                hash ^= passwordCharacters[charIndex];
            }
            // also hash with charcount
            hash = ((hash >> 14) & 0x01) | ((hash << 1) & 0x7fff);
            hash ^= passwordCharacters.length;
            hash ^= (0x8000 | ('N' << 8) | 'K');
        }
        return (short) hash;
    }
}

Related

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