summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/auth/keys.ex8
-rw-r--r--lib/auth/password.ex7
-rw-r--r--lib/chessh.ex2
-rw-r--r--lib/chessh/auth/keys.ex10
-rw-r--r--lib/chessh/auth/password.ex12
-rw-r--r--lib/chessh/schema/player.ex (renamed from lib/schema/player.ex)0
-rw-r--r--lib/chessh/schema/repo.ex (renamed from lib/schema/repo.ex)0
7 files changed, 22 insertions, 17 deletions
diff --git a/lib/auth/keys.ex b/lib/auth/keys.ex
deleted file mode 100644
index 3e0f142..0000000
--- a/lib/auth/keys.ex
+++ /dev/null
@@ -1,8 +0,0 @@
-defmodule Chessh.Auth.KeyAuthenticator do
- use Sshd.PublicKeyAuthenticator
- require Logger
-
- def authenticate(_, _, _) do
- false
- end
-end
diff --git a/lib/auth/password.ex b/lib/auth/password.ex
deleted file mode 100644
index 5e31b33..0000000
--- a/lib/auth/password.ex
+++ /dev/null
@@ -1,7 +0,0 @@
-defmodule Chessh.Auth.PasswordAuthenticator do
- use Sshd.PasswordAuthenticator
-
- def authenticate(_username, _password) do
- true
- end
-end
diff --git a/lib/chessh.ex b/lib/chessh.ex
index 42bb21f..82d0cfc 100644
--- a/lib/chessh.ex
+++ b/lib/chessh.ex
@@ -1,6 +1,4 @@
defmodule Chessh do
- require Logger
-
def hello() do
:world
end
diff --git a/lib/chessh/auth/keys.ex b/lib/chessh/auth/keys.ex
new file mode 100644
index 0000000..d85f4a4
--- /dev/null
+++ b/lib/chessh/auth/keys.ex
@@ -0,0 +1,10 @@
+defmodule Chessh.Auth.KeyAuthenticator do
+ use Sshd.PublicKeyAuthenticator
+ require Logger
+
+ def authenticate(username, public_key, _opts) do
+ Logger.debug("#{inspect(username)}")
+ Logger.debug("#{inspect(public_key)}")
+ true
+ end
+end
diff --git a/lib/chessh/auth/password.ex b/lib/chessh/auth/password.ex
new file mode 100644
index 0000000..a6fa73d
--- /dev/null
+++ b/lib/chessh/auth/password.ex
@@ -0,0 +1,12 @@
+defmodule Chessh.Auth.PasswordAuthenticator do
+ alias Chessh.Player
+ alias Chessh.Repo
+ use Sshd.PasswordAuthenticator
+
+ 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)
+ end
+ end
+end
diff --git a/lib/schema/player.ex b/lib/chessh/schema/player.ex
index 7d9bb6e..7d9bb6e 100644
--- a/lib/schema/player.ex
+++ b/lib/chessh/schema/player.ex
diff --git a/lib/schema/repo.ex b/lib/chessh/schema/repo.ex
index 27d81b9..27d81b9 100644
--- a/lib/schema/repo.ex
+++ b/lib/chessh/schema/repo.ex