summaryrefslogtreecommitdiff
path: root/lib/chessh/auth
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chessh/auth')
-rw-r--r--lib/chessh/auth/keys.ex17
-rw-r--r--lib/chessh/auth/password.ex4
2 files changed, 15 insertions, 6 deletions
diff --git a/lib/chessh/auth/keys.ex b/lib/chessh/auth/keys.ex
index d85f4a4..a948fdf 100644
--- a/lib/chessh/auth/keys.ex
+++ b/lib/chessh/auth/keys.ex
@@ -1,10 +1,19 @@
defmodule Chessh.Auth.KeyAuthenticator do
+ alias Chessh.Key
+ alias Chessh.Repo
use Sshd.PublicKeyAuthenticator
require Logger
+ import Ecto.Query
- def authenticate(username, public_key, _opts) do
- Logger.debug("#{inspect(username)}")
- Logger.debug("#{inspect(public_key)}")
- true
+ def authenticate(username, public_key) do
+ !!Repo.one(
+ from(k in Key,
+ join: p in assoc(k, :player),
+ where: k.key == ^Key.encode_key(public_key),
+ where: p.username == ^String.Chars.to_string(username)
+ )
+ )
end
+
+ def authenticate(username, public_key, _opts), do: authenticate(username, public_key)
end
diff --git a/lib/chessh/auth/password.ex b/lib/chessh/auth/password.ex
index a6fa73d..48a4d62 100644
--- a/lib/chessh/auth/password.ex
+++ b/lib/chessh/auth/password.ex
@@ -2,11 +2,11 @@ defmodule Chessh.Auth.PasswordAuthenticator do
alias Chessh.Player
alias Chessh.Repo
use Sshd.PasswordAuthenticator
+ require Logger
def authenticate(username, password) do
case Repo.get_by(Player, username: String.Chars.to_string(username)) do
- nil -> false
- x -> Player.valid_password?(x, password)
+ x -> Player.valid_password?(x, String.Chars.to_string(password))
end
end
end