diff options
| author | Simponic <loganhunt@simponic.xyz> | 2022-12-19 02:39:40 -0700 |
|---|---|---|
| committer | Simponic <loganhunt@simponic.xyz> | 2022-12-19 02:39:40 -0700 |
| commit | b4743f9efb685545cdd780cc9ba7a50e083dd8cf (patch) | |
| tree | a538467211886df38c79706769029e23c7aadb61 /lib/chessh/auth | |
| parent | 9cdfb6eb9cd30c4e06a7d9fef53e519983827d81 (diff) | |
| download | chessh-b4743f9efb685545cdd780cc9ba7a50e083dd8cf.tar.gz chessh-b4743f9efb685545cdd780cc9ba7a50e083dd8cf.zip | |
Get public key authenticator actually running, add password validator via hash
Diffstat (limited to 'lib/chessh/auth')
| -rw-r--r-- | lib/chessh/auth/keys.ex | 10 | ||||
| -rw-r--r-- | lib/chessh/auth/password.ex | 12 |
2 files changed, 22 insertions, 0 deletions
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 |
