1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Plugs.AuthenticationPlug do
15 def checkpw(password, password_hash) do
17 String.starts_with?(password_hash, "$pbkdf2") ->
18 Pbkdf2.checkpw(password, password_hash)
19 String.starts_with?(password_hash, "$6") ->
20 :crypt.crypt(password, password_hash) == password_hash
22 Logger.error("Password hash not recognized")
27 def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
32 auth_user: %{password_hash: password_hash} = auth_user,
33 auth_credentials: %{password: password}
38 if Pbkdf2.checkpw(password, password_hash) do
40 |> assign(:user, auth_user)
46 def call(%{assigns: %{auth_credentials: %{password: _}}} = conn, _) do
47 Pbkdf2.dummy_checkpw()
51 def call(conn, _), do: conn