ExkPasswd.Strength (ExkPasswd v0.1.1)

View Source

Password strength assessment based on entropy calculations.

Provides quantitative strength metrics as pure data, leaving presentation and internationalization to consumers.

Examples

iex> config = ExkPasswd.Config.new!(num_words: 3)
...> password = ExkPasswd.generate(config)
...> result = ExkPasswd.Strength.analyze(password, config)
...> result.rating in [:excellent, :good, :fair, :weak]
true
iex> result.score >= 0 and result.score <= 100
true

Summary

Functions

Analyze password strength based on entropy.

Quick strength check - returns just the rating.

Types

rating()

@type rating() :: :excellent | :good | :fair | :weak

result()

@type result() :: %{rating: rating(), score: 0..100, entropy_bits: float()}

Functions

analyze(password, settings)

@spec analyze(String.t(), ExkPasswd.Config.t()) :: result()

Analyze password strength based on entropy.

Returns a strength assessment with rating, score, and entropy measurement. Consumers can use this data to build their own UI, messages, or localization.

Parameters

  • password - The password to analyze
  • config - The Config struct used to generate the password

Returns

A result map containing:

  • rating - Strength rating (:excellent, :good, :fair, or :weak)
  • score - Normalized score from 0 to 100
  • entropy_bits - Effective entropy in bits (conservative estimate)

Examples

iex> config = ExkPasswd.Config.new!(num_words: 4)
...> password = "test-PASS-word-HERE"
...> result = ExkPasswd.Strength.analyze(password, config)
...> is_map(result)
true
iex> Map.keys(result) |> Enum.sort()
[:entropy_bits, :rating, :score]

rating(password, settings)

@spec rating(String.t(), ExkPasswd.Config.t()) :: rating()

Quick strength check - returns just the rating.

Convenience function when you only need the rating category without score or entropy details.

Parameters

  • password - Password to check
  • config - Config used to generate it

Returns

Strength rating atom (:excellent, :good, :fair, or :weak)

Examples

iex> config = ExkPasswd.Config.new!(num_words: 6)
...> password = ExkPasswd.generate(config)
...> rating = ExkPasswd.Strength.rating(password, config)
...> rating in [:excellent, :good, :fair, :weak]
true