Users

In the Schemas section, we defined the Accounts.User schema with a virtual password field. This is useful whenever you want your schema to have a field but you don't want it to be persisted.

We never want to store user passwords in plain text. The idea here is to temporarily place the plain text password on this password field, which will be then hashed and inserted as the value of the hashed_password field in the last step of our User.create_changeset/2 function:

$ cat apps/elixir_drip/lib/elixir_drip/accounts/user.exdefmodule ElixirDrip.Accounts.User do  # ...  @email_regex ~r/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i  def create_changeset(%User{} = user, attrs) do    user    |> cast(attrs, [:username, :password, :email]) |> validate_required([:username, ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.