Uses PBKDF2WithHmacSHA1 to hash the password using the given salt,
returning the has in encoded hexadecimal form. If the password is empty,
returns the salt.
333412
public static String computePasswordHash(final String password, final byte[] salt) {
    if (StringMan.isEmpty(password))
      return (StringMan.encodeBytesToString(salt));
    final KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 2048, 160);
    SecretKeyFactory f;
    try {
      f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
      final byte[] hash = f.generateSecret(spec).getEncoded();
      return StringMan.encodeBytesToString(hash);
    } catch (final NoSuchAlgorithmException ex) {
      throw new RuntimeException("Missing encryption algorithm:", ex);
    } catch (final InvalidKeySpecException ex) {
      throw new RuntimeException("Key spec is incorrect.", ex);
    }
  }
1003752
def hash_password(self, plain_password):
        """"""
        salt = uuid.uuid4().hex
        encrypted_password = self.get_hash(salt, plain_password)
        return salt + '$' + encrypted_password
504717
def _get_hash():
    '''
    
    '''
    # Using bitmask to emulate rollover behavior of C unsigned 32 bit int
    bitmask = 0xffffffff
    h = 0

    for i in bytearray(salt.utils.stringutils.to_bytes(__grains__['id'])):
        h = (h + i) & bitmask
        h = (h + (h << 10)) & bitmask
        h = (h ^ (h >> 6)) & bitmask

    h = (h + (h << 3)) & bitmask
    h = (h ^ (h >> 11)) & bitmask
    h = (h + (h << 15)) & bitmask

    return (h & (_HASH_SIZE - 1)) & bitmask
291661
def scrypt(password, salt='', n=2**20, r=8, p=1,
           maxmem=2**25, dklen=64):
    
    return nacl.bindings.crypto_pwhash_scryptsalsa208sha256_ll(
        password, salt, n, r, p, maxmem=maxmem, dklen=dklen)
871360
public static String computePasswordHash(final String password, final String salt) {
    return computePasswordHash(password, stringToSalt(salt));
  }
398991
function hash_password(values, next) {
  // If no password was provided, just move on and exit.
  if (!values.password || values.password.length > 1000) {
    return next()
  }

  this
    .findOne(values)
    .then(user => {
      // Create a salt for this user if they don't have one.
      const salt = user && user.salt ? user.salt : utils.create_salt()

      // We're going to encrypt the password.
      utils.hash_password(values.password, salt, (password, salt) => {
        // Apply the hash and salt to the inbound values.
        values.password = password.toString("hex")
        values.salt = salt
        values.requires_password = false


        // Move on.
        next()
      })
    })
    .catch(next)
}
1191821
public static String createHash(char[] password) throws NoSuchAlgorithmException, InvalidKeySpecException {

    final SecureRandom random = new SecureRandom();
    final byte[] salt = new byte[SALT_BYTES];
    random.nextBytes(salt);

    final byte[] hash = pbkdf2(password, salt, PBKDF2_ITERATIONS, HASH_BYTES);
    // format iterations:salt:hash
    return PBKDF2_ITERATIONS + ":" + toHex(salt) + ":" + toHex(hash);
  }
972245
def check_password(self, hashed_password, plain_password):
        
        salt, encrypted_password = hashed_password.split('$')
        re_encrypted_password = self.get_hash(salt, plain_password)
        return encrypted_password == re_encrypted_password
1201753
public function verifyPasswordHash(string $password, string $hash, string $salt = ''): string
    {
        $password = ($salt ?: self::$salt) . trim($password);

        return password_verify($password, $hash);
    }
1325613
def check_password(raw_password, enc_password):
    
    l = enc_password.split('$')
    #only password of built-in user can split to 3
    if len(l)==3:
        algo, salt, hsh = l
        return hsh == get_hexdigest(algo, salt, raw_password)
    else:
        return False
458869
public static String getSHA1Hash(final String input) throws HibiscusException  {

        String hashValue = null;

        try {

            final MessageDigest messageDigest = MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA1);
            byte[] sha1Hash = new byte[BYTE_LENGTH_SHA1];

            messageDigest.update(input.getBytes(ENCODING_CHARSET_NAME), MESSAGE_DIGEST_UPDATE_OFFSET, input.length());
            sha1Hash = messageDigest.digest();

            hashValue = convertToHex(sha1Hash);

        } catch (NoSuchAlgorithmException e) {
            throw new HibiscusException("Unsupported Message Digest Algorithm "  + MESSAGE_DIGEST_ALGORITHM_SHA1, e);
        } catch (UnsupportedEncodingException e) {
            throw new HibiscusException("Unsupported Encoding " + ENCODING_CHARSET_NAME , e);
        }

        return hashValue;
    }
387888
def decrypt_PBEWithSHAAndTwofishCBC(encrypted_data, password, salt, iteration_count):
    
    iv  = derive_key(hashlib.sha1, PURPOSE_IV_MATERIAL,  password, salt, iteration_count, 16)
    key = derive_key(hashlib.sha1, PURPOSE_KEY_MATERIAL, password, salt, iteration_count, 256//8)

    encrypted_data = bytearray(encrypted_data)
    encrypted_data_len = len(encrypted_data)
    if encrypted_data_len % 16 != 0:
        raise BadDataLengthException("encrypted data length is not a multiple of 16 bytes")

    plaintext = bytearray()

    # slow and dirty CBC decrypt
    from twofish import Twofish
    cipher = Twofish(key)

    last_cipher_block = bytearray(iv)
    for block_offset in range(0, encrypted_data_len, 16):
        cipher_block = encrypted_data[block_offset:block_offset+16]
        plaintext_block = xor_bytearrays(bytearray(cipher.decrypt(bytes(cipher_block))), last_cipher_block)
        plaintext.extend(plaintext_block)
        last_cipher_block = cipher_block

    plaintext = strip_pkcs7_padding(plaintext, 16)
    return bytes(plaintext)
507459
function (password, algorithm, salt) {
            salt = salt || Crypto.randomBytes(128).toString("hex");
            algorithm = algorithm || this.$.algorithm;

            var hash = Crypto.createHash(this.$.algorithm);
            hash.update(salt + password, "utf8");

            return [algorithm, salt, hash.digest("hex")].join(this.$.delimiter);
        }
845542
def password_hash(password):
    
    try:
        return bcrypt_sha256.encrypt(password)
    except TypeError:
        return bcrypt_sha256.encrypt(password.decode('utf-8'))
221226
public function encode( $password, $salt = null )
	{
		return ( isset( $this->hasher ) ? $this->hasher->getHashedPassword( $password, $salt ) : $password );
	}
418778
async function _pbkdf2Passphrase(passphrase, salt) {
  if (window.crypto && window.crypto.subtle) {
    console.log('[crypt] Using native PBKDF2');

    const k = await window.crypto.subtle.importKey(
      'raw',
      Buffer.from(passphrase, 'utf8'),
      { name: 'PBKDF2' },
      false,
      ['deriveBits'],
    );

    const algo = {
      name: 'PBKDF2',
      salt: Buffer.from(salt, 'hex'),
      iterations: DEFAULT_PBKDF2_ITERATIONS,
      hash: 'SHA-256',
    };

    const derivedKeyRaw = await window.crypto.subtle.deriveBits(algo, k, DEFAULT_BYTE_LENGTH * 8);
    return Buffer.from(derivedKeyRaw).toString('hex');
  } else {
    console.log('[crypt] Using Forge PBKDF2');
    const derivedKeyRaw = forge.pkcs5.pbkdf2(
      passphrase,
      forge.util.hexToBytes(salt),
      DEFAULT_PBKDF2_ITERATIONS,
      DEFAULT_BYTE_LENGTH,
      forge.md.sha256.create(),
    );

    return forge.util.bytesToHex(derivedKeyRaw);
  }
}
1261073
private function hashModePbkdf2($password)
    {
        $this->cwsDebug->titleH2('Create password hash using PBKDF2');
        $this->cwsDebug->labelValue('Password', $password);

        $salt = $this->random(self::PBKDF2_RANDOM_BYTES);
        $this->cwsDebug->labelValue('Salt', $salt);

        $algorithm = $this->encode(self::PBKDF2_ALGORITHM);
        $this->cwsDebug->labelValue('Algorithm', self::PBKDF2_ALGORITHM);

        $ite = rand(self::PBKDF2_MIN_ITE, self::PBKDF2_MAX_ITE);
        $this->cwsDebug->labelValue('Iterations', $ite);
        $ite = $this->encode(rand(self::PBKDF2_MIN_ITE, self::PBKDF2_MAX_ITE));

        $params = $algorithm.self::PBKDF2_SEPARATOR;
        $params .= $ite.self::PBKDF2_SEPARATOR;
        $params .= $salt.self::PBKDF2_SEPARATOR;

        $hash = $this->getPbkdf2($algorithm, $password, $salt, $ite, self::PBKDF2_HASH_BYTES, true);
        $this->cwsDebug->labelValue('Hash', $hash);
        $this->cwsDebug->labelValue('Length', strlen($hash));

        $finalHash = $params.base64_encode($hash);
        $this->cwsDebug->dump('Encoded hash (length : '.strlen($finalHash).')', $finalHash);

        if (strlen($finalHash) == self::PBKDF2_LENGTH) {
            return $finalHash;
        }

        $this->error = 'Cannot generate the PBKDF2 password hash...';
        $this->cwsDebug->error($this->error);
    }