pbkdf2_elixir v1.0.2 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.

Link to this function

hash_password(password, salt, opts \\ []) View Source

Hash a password using Pbkdf2.

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
  • :format - 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
Link to this function

verify_pass(password, hash, salt, digest, rounds, output_fmt) View Source

Verify a password by comparing it with the stored Pbkdf2 hash.