ExkPasswd.Password (ExkPasswd v0.3.0)

View Source

Orchestrates password generation from a validated configuration.

This module orchestrates the password generation process using:

  1. Indexed word selection from the configured dictionary
  2. Pre-transformed case variants for common modes
  3. Optional character substitutions
  4. Configurable dictionary support (default EFF or custom)

All random operations use cryptographically secure random number generation.

Security

This module uses ExkPasswd.Random, ExkPasswd.Dictionary, and ExkPasswd.Token which all rely on :crypto.strong_rand_bytes/1 for cryptographic security.

Examples

iex> password = ExkPasswd.Password.create()
...> is_binary(password) and String.length(password) > 0
true

iex> config = ExkPasswd.Config.new!(num_words: 2, separator: "-")
...> password = ExkPasswd.Password.create(config)
...> String.contains?(password, "-")
true

Summary

Functions

Create a password based on the config either passed in or the default config.

Create a password using a stateful Buffer generator.

Functions

create(config \\ Config.new!())

@spec create(ExkPasswd.Config.t()) :: String.t()

Create a password based on the config either passed in or the default config.

Validates the config and uses cryptographically secure random generation for every random choice made by the built-in pipeline.

Parameters

Returns

A randomly generated password string.

Examples

iex> password = ExkPasswd.Password.create()
...> is_binary(password) and String.length(password) > 0
true

iex> config = ExkPasswd.Config.new!(num_words: 2, separator: "-")
...> password = ExkPasswd.Password.create(config)
...> String.contains?(password, "-")
true

create_with_state(config, random_state)

@spec create_with_state(ExkPasswd.Config.t(), ExkPasswd.Buffer.t()) ::
  {String.t(), ExkPasswd.Buffer.t()}

Create a password using a stateful Buffer generator.

This is an optimized version for batch generation that accepts and returns a Buffer state, reducing the number of :crypto.strong_rand_bytes/1 syscalls.

Parameters

Returns

A tuple of {password, new_random_state}

Examples

iex> state = ExkPasswd.Buffer.new(1000)
...>
...> {password, _new_state} =
...>   ExkPasswd.Password.create_with_state(ExkPasswd.Config.new!(), state)
...>
...> is_binary(password) and String.length(password) > 0
true