Next | Previous

bcrypt

This module provides functions for generating and verifying bcrypt hashes as well as functions for getting informations from a bcrypt hash.

Properties

  • DEFAULT_LOG2_ROUNDSnumber:

    Default log2 rounds (default: 10).

  • MAX_EXECUTION_TIMEnumber:

    Maximum execution time for each cipher iteration in milliseconds (default: 100).

Functions

hash(str, salt_length)

Generates a hash for the given string. If salt_length is not given, the length of the salt will be equal to DEFAULT_LOG2_ROUNDS.

Parameters
  • string str
  • number? salt_length
Returns
  • string
Raises Exception
  • Exception @returns

compare(str, known_hash)

Tests a string against a known hash.

Parameters
  • string str
  • string known_hash
Returns
  • bool
Raises Exception
  • Exception @returns

get_rounds(hash)

Gets the number of rounds used to encrypt the specified hash.

Parameters
  • string hash
Returns
  • number
Raises Exception
  • Exception @returns

get_salt(hash)

Gets the salt portion from a hash.

Parameters
  • string hash
Returns
  • string
Notes
  • This function does not validate the hash.
Raises Exception
  • Exception @returns