# XKPassword

Generate memorable, word-based passwords in Elixir or from the command line.
The library uses the dictionary and presets from the [Ruby gem](https://github.com/jdeen/xkpassword).

## Elixir library

Requires Elixir 1.17 or later. Add XKPassword to your Mix dependencies.

```elixir
{:xkpassword, "~> 0.1.0"}
```

```elixir
XKPassword.generate()
XKPassword.generate(preset: :security, separator: ".")
XKPassword.generate(words: 5, min_length: 5, max_length: 8, case_transform: :capitalize)
```

`generate/1` takes a keyword list or an atom-keyed map. Explicit options override
preset defaults. Presets accept atoms or strings such as `"apple-id"`. Use
`:upcase`, `:downcase`, or `:capitalize` to apply the same transform to every
word, or `nil` to randomly uppercase each word. Use `separator: ""` to join
words directly.

| Preset | Words | Word length | Separator | Case |
| --- | ---: | --- | --- | --- |
| `:xkcd` (default) | 4 | 4–8 | Hyphen | Random per word |
| `:web32` | 4 | 4–5 | Hyphen | Random per word |
| `:wifi` | 6 | 4–8 | Hyphen | Random per word |
| `:security` | 6 | 4–8 | Space | Lowercase |
| `:apple_id` | 3 | 4–7 | Hyphen | Random per word |

The library uses Erlang's `:crypto` to choose a length and then a word of that
length for each position. The dictionary is embedded at compile time.

## Command line

Build an executable from a checkout.

```sh
mix deps.get
mix escript.build
./xkpassword
./xkpassword --preset apple-id --separator .
./xkpassword --help
```

To install it on your path, run `mix escript.install hex xkpassword`
and include `~/.mix/escripts` (or `$MIX_HOME/escripts`) on your `PATH`.

The CLI reads optional YAML defaults from `~/.xkpassword`, the same file used by
the Ruby CLI. `xkpassword --init` creates a commented template. CLI flags override
file settings, and both override preset defaults.

```yaml
preset: security
words: 5
min_length: 4
max_length: 8
separator: "-"
case_transform: capitalize
```

Use `--words`, `--min-length`, and `--max-length` with integers. The
selected range must contain dictionary words at every length.

## License

[MIT](https://github.com/ziyan-junaideen/ex_xkpassword/blob/main/LICENSE)
