You can change the user struct by using user = %{ user | failed_login_tries: user.failed_login_tries + 1} and to persist this in the database use Repo.update by passing it an updated ecto changeset. Immutability refers to the fact that the previous struct remains the same. e.g.
defmodule User do
defstruct [:email]
end
u1 = %User{email: "mujju"}
u2 = u1
u2 = %{u2 | email: "danny"}
IO.inspect(u1)
# => %User{email: "mujju"}
IO.inspect(u2)
# => %User{email: "danny"}






















