summaryrefslogtreecommitdiff
path: root/lib/chessh/auth/password.ex
blob: a01291de6475c02abdab9e4d45fcdf8c9762d515 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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) do
    case Repo.get_by(Player, username: username) do
      player -> authenticate(player, password)
      nil -> false
    end
  end
end