pbkdf2_elixir v0.11.0 Pbkdf2.Base View Source
Base module for the Pbkdf2 password hashing library.
Link to this section Summary
Functions
Generate a salt for use with Django’s version of pbkdf2
Hash a password using Pbkdf2
Verify a password by comparing it with the stored Pbkdf2 hash
Link to this section Functions
Generate a salt for use with Django’s version of pbkdf2.
Examples
To create a valid Django hash, using pbkdf2_sha256:
salt = django_salt(12)
opts = [digest: :sha256, format: :django]
Pbkdf2.Base.hash_password(password, salt, opts)
This example uses 160_000 rounds. Add rounds: number
to the opts
if you want to change the number of rounds.
Hash a password using Pbkdf2.
Configurable parameters
The following parameter can be set in the config file:
rounds - computational cost
- the number of rounds
- 160_000 is the default
If you are hashing passwords in your tests, it can be useful to add
the following to the config/test.exs
file:
config :pbkdf2_elixir,
rounds: 1
NB. do not use this value in production.
Options
There are four options (rounds can be used to override the value in the config):
rounds - the number of rounds
- the amount of computation, given in number of iterations
- the default is 160_000
- this can also be set in the config file
output_fmt - the output format of the hash
- the default is modular crypt format
digest - the sha algorithm that pbkdf2 will use
- the default is sha512
length - the length, in bytes, of the hash
- the default is 64 for sha512 and 32 for sha256
Verify a password by comparing it with the stored Pbkdf2 hash.