Powered by AppSignal & Oban Pro

ExkPasswd quick start

notebooks/quickstart.livemd

ExkPasswd quick start

Mix.install([
  {:exk_passwd, "~> 0.2.0"}
])

ExkPasswd combines independent random words with optional digits, separators, padding, and transforms. All password material comes from the Erlang/OTP cryptographic random source.

Generate a password

ExkPasswd.generate()

Built-in presets cover a few common compatibility targets:

for preset <- [:default, :xkcd, :web32, :wifi, :apple_id, :security] do
  {preset, ExkPasswd.generate(preset)}
end

web16 is available for sites with a strict 16-character maximum, but its output space is much smaller than the other presets.

Create a configuration

config =
  ExkPasswd.Config.new!(
    num_words: 4,
    word_length: 5..7,
    case_transform: :capitalize,
    separator: "-",
    digits: {2, 2},
    padding: %{char: "!@#", before: 1, after: 1, to_length: 0}
  )

ExkPasswd.generate(config)

Invalid options return a tagged error with new/1 or raise ArgumentError with new!/1:

ExkPasswd.Config.new(num_words: 0)

Generate a batch

config = ExkPasswd.Config.Presets.get(:xkcd)

passwords = ExkPasswd.Batch.generate_batch(5, config)
{passwords, length(Enum.uniq(passwords))}

Use generate_unique_batch/3 when distinct values are a requirement. It raises if the configured output space cannot satisfy the request within the attempt limit.

Inspect the security estimate

password = ExkPasswd.generate(config)
report = ExkPasswd.Entropy.calculate(password, config)

%{
  password: password,
  seen_min_entropy: Float.round(report.seen, 2),
  blind_search_space_estimate: Float.round(report.blind, 2),
  rating: report.status
}

seen assumes an attacker knows the generator and configuration. blind is a character-class brute-force heuristic, not measured entropy.

Continue