summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/config.exs12
-rw-r--r--config/dev.exs8
-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
-rw-r--r--mix.exs1
-rw-r--r--test/chessh_test.exs4
-rw-r--r--test/server_test.exs8
12 files changed, 37 insertions, 35 deletions
diff --git a/config/config.exs b/config/config.exs
index 807824a..61bf72f 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -1,11 +1,19 @@
import Config
+config :chessh, Chessh.Repo,
+ database: "chessh",
+ username: "postgres",
+ password: "postgres",
+ hostname: "localhost"
+
+config :chessh, ecto_repos: [Chessh.Repo]
+
config :esshd,
enabled: true,
priv_dir: Path.join(Path.dirname(__DIR__), "priv/keys"),
handler: {Chessh.Shell, :on_shell, 4},
port: 42069,
- public_key_authenticator: Chessh.Auth.KeyAuthenticator,
- password_authenticator: Chessh.Auth.PasswordAuthenticator
+ password_authenticator: Chessh.Auth.PasswordAuthenticator,
+ public_key_authenticator: Chessh.Auth.KeyAuthenticator
import_config "#{config_env()}.exs"
diff --git a/config/dev.exs b/config/dev.exs
index f71d02e..becde76 100644
--- a/config/dev.exs
+++ b/config/dev.exs
@@ -1,9 +1 @@
import Config
-
-config :chessh, Chessh.Repo,
- database: "chessh",
- username: "postgres",
- password: "postgres",
- hostname: "localhost"
-
-config :chessh, ecto_repos: [Chessh.Repo]
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
diff --git a/mix.exs b/mix.exs
index 01a7a6b..b73b943 100644
--- a/mix.exs
+++ b/mix.exs
@@ -14,6 +14,7 @@ defmodule Chessh.MixProject do
# Run "mix help compile.app" to learn about applications.
def application do
[
+ mod: {Chessh.Application, []},
extra_applications: [:esshd, :logger]
]
end
diff --git a/test/chessh_test.exs b/test/chessh_test.exs
new file mode 100644
index 0000000..0fa7da8
--- /dev/null
+++ b/test/chessh_test.exs
@@ -0,0 +1,4 @@
+defmodule ChesshTest do
+ use ExUnit.Case
+ doctest Chessh
+end
diff --git a/test/server_test.exs b/test/server_test.exs
deleted file mode 100644
index d710e5c..0000000
--- a/test/server_test.exs
+++ /dev/null
@@ -1,8 +0,0 @@
-defmodule ChesshTest do
- use ExUnit.Case
- doctest Chessh
-
- test "greets the world" do
- assert Chessh.hello() == :world
- end
-end