chessh/lib/chessh/auth/password.ex
2023-01-03 16:47:27 -07:00

16 lines
415 B
Elixir

defmodule Chessh.Auth.PasswordAuthenticator do
alias Chessh.{Player, Repo}
def authenticate(player = %Player{}, password) do
Player.valid_password?(player, password)
end
def authenticate(username, _password) when is_nil(username), do: false
def authenticate(username, password) do
case Repo.get_by(Player, username: username) do
player -> authenticate(player, password)
end
end
end