summaryrefslogtreecommitdiff
path: root/lib/chessh/auth
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-12-30 05:53:15 -0700
committerGitHub <noreply@github.com>2022-12-30 05:53:15 -0700
commit52fbc0b0161d2d30583d7f04eef57a29e441e1d2 (patch)
treef882037a2820973ba6dc5f64206b01dba03266d8 /lib/chessh/auth
parentc143bb549c53f2737c41cdfce6cc2598c5489bdc (diff)
parente7d8c61487815bd90ec5834dad5e6f64dd951b53 (diff)
downloadchessh-52fbc0b0161d2d30583d7f04eef57a29e441e1d2.tar.gz
chessh-52fbc0b0161d2d30583d7f04eef57a29e441e1d2.zip
Merge pull request #2 from Simponic/erlang_ssh_server
Erlang ssh server #2
Diffstat (limited to 'lib/chessh/auth')
-rw-r--r--lib/chessh/auth/keys.ex11
-rw-r--r--lib/chessh/auth/password.ex6
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/chessh/auth/keys.ex b/lib/chessh/auth/keys.ex
index a29d169..f0e1c78 100644
--- a/lib/chessh/auth/keys.ex
+++ b/lib/chessh/auth/keys.ex
@@ -1,7 +1,16 @@
defmodule Chessh.Auth.KeyAuthenticator do
- alias Chessh.{Key, Repo}
+ alias Chessh.{Key, Repo, Player}
import Ecto.Query
+ def authenticate(player = %Player{}, public_key) do
+ !!Repo.one(
+ from(k in Key,
+ where: k.key == ^Key.encode_key(public_key),
+ where: k.player_id == ^player.id
+ )
+ )
+ end
+
def authenticate(username, public_key) do
!!Repo.one(
from(k in Key,
diff --git a/lib/chessh/auth/password.ex b/lib/chessh/auth/password.ex
index ea2c8fc..0986169 100644
--- a/lib/chessh/auth/password.ex
+++ b/lib/chessh/auth/password.ex
@@ -1,9 +1,13 @@
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
- x -> Player.valid_password?(x, password)
+ player -> authenticate(player, password)
end
end
end