# `Ex2FA.Changeset`
[🔗](https://github.com/Ultraluv/ex_2FA/blob/v0.1.0/lib/ex_2fa/changeset.ex#L2)

Ecto.Changeset helper functions for inserting or regenerating a 2FA secret.

API-compatible with `NioGoogleAuthenticator.Changeset`. This module is
automatically compiled when `:ecto` is available in your project.

# `add_secret_to_changeset`

```elixir
@spec add_secret_to_changeset(Ecto.Changeset.t(), atom(), keyword()) ::
  Ecto.Changeset.t()
```

Adds a secret to an `Ecto.Changeset` if the target field is currently `nil`.

Defaults to `:ga_secret` for compatibility with `nio_google_authenticator`.
You may pass a custom field atom as the second argument, and optional
`:byte_length` in `options` (default `10`).

## Examples

    user
    |> cast(params, [:name, :ga_secret])
    |> Ex2FA.Changeset.add_secret_to_changeset()

    user
    |> cast(params, [:name, :totp_secret])
    |> Ex2FA.Changeset.add_secret_to_changeset(:totp_secret, byte_length: 20)

# `regenerate_secret_in_changeset`

```elixir
@spec regenerate_secret_in_changeset(Ecto.Changeset.t(), atom(), keyword()) ::
  Ecto.Changeset.t()
```

Regenerates and replaces the secret on an `Ecto.Changeset`, regardless of
whether a value already exists.

Defaults to `:ga_secret` for compatibility with `nio_google_authenticator`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
