Authentication Plug: Update bcrypt password on login.

This commit is contained in:
lain 2020-05-17 10:31:01 +02:00
commit baef35bcc8
2 changed files with 25 additions and 6 deletions

View file

@ -30,6 +30,17 @@ defmodule Pleroma.Plugs.AuthenticationPlug do
false
end
def maybe_update_password(%User{password_hash: "$2" <> _} = user, password) do
user
|> User.password_update_changeset(%{
"password" => password,
"password_confirmation" => password
})
|> Pleroma.Repo.update()
end
def maybe_update_password(user, _), do: {:ok, user}
def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
def call(
@ -42,6 +53,8 @@ defmodule Pleroma.Plugs.AuthenticationPlug do
_
) do
if checkpw(password, password_hash) do
{:ok, auth_user} = maybe_update_password(auth_user, password)
conn
|> assign(:user, auth_user)
|> OAuthScopesPlug.skip_plug()