ex_bcrypt v0.0.1 ExBcrypt

bcrypt password hashing algorithm.

Summary

Functions

Changes the work factor of a hash

Change a password, only if the previous one was given with it

Hashes a given password with a given work factor

Compares a given password to a hash

Generates a salt with a given work factor

The time bcrypt takes to hash the string ‘password’ in relation with a given work factor. Returns a tuple in the form of: {:ok, work_factor, elapsed_time_in_ms}

Functions

change_factor(password, hash, factor)

Specs

change_factor(binary, binary, pos_integer) ::
  bitstring |
  Exception.t

Changes the work factor of a hash.

If a given password matches a given hash, the password is re-hashed again using the new work_factor.

change_password(old, hash, new, factor \\ 12)

Specs

change_password(binary, binary, binary, pos_integer) ::
  bitstring |
  Exception.t

Change a password, only if the previous one was given with it.

If a given old password matches a given old hash, a new password is hashed using the work factor passed in as an argument. (Defaults to 12)

hash(password, factor \\ 12)

Specs

hash(binary, pos_integer) :: binary | Exception.t

Hashes a given password with a given work factor.

Bcrypt takes care of salting the hashes for you so this does not need to be done. The higher the work factor, the longer the password will take to be hashed and checked. The work factor defaults to 12 if no factor is given. The work factor should be between 4 and 31.

match(password, hash)

Specs

match(binary, binary) :: boolean | Exception.t

Compares a given password to a hash.

Returns true if the password matches, false otherwise. The comparison is done in constant time (based on the hash length).

salt(factor \\ 12)

Specs

salt(pos_integer) :: bitstring | Exception.t

Generates a salt with a given work factor.

The work factor defaults to 12 if no factor is given. The work factor should be between 4 and 31.

time(factor \\ 12)

Specs

time(pos_integer) ::
  {:ok, pos_integer, number} |
  Exception.t

The time bcrypt takes to hash the string ‘password’ in relation with a given work factor. Returns a tuple in the form of: {:ok, work_factor, elapsed_time_in_ms}

The work factor defaults to 12 if no factor is given. The work factor should be between 4 and 31.