ExkPasswd.Password (ExkPasswd v0.2.0)

View Source

Password generation with optimized performance.

This module orchestrates the password generation process using:

  1. Constant-time word selection from tuple-based dictionary
  2. Pre-transformed case variants (eliminates runtime transformation)
  3. Character substitutions (leetspeak) for increased complexity
  4. Configurable dictionary support (default EFF or custom)

All random operations use cryptographically secure random number generation.

Implementation

  • Word selection: Tuple-based constant-time access
  • Case transformation: Pre-computed variants eliminate runtime processing
  • Efficient generation: Optimized dictionary lookups and transformations

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.

Uses cryptographically secure random generation for all randomness and tuple-based constant-time word selection for efficient generation.

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