Bcrypt php user to plaroma
Hello, I'm having trouble customizing the code.
I have a legacy platform developed in php, where users have the password generated by php's password_hash(), in this case it is bcrypt of 12, example of a password:
$2y10
lI97.QOnKcuUJmb5GOQvJ.VvV8QVl7QMPUSEid8D82Ahy5pFvipCK
As it starts with the $2 prefix, it was for the plaroma to analyze it as bcrypt and then update to the new standard, however it informs that the password is wrong, so to work around that I thought of creating a column called legacy_password and then modifying the pleroma_authenticator. ex for it to analyze the column and if it has been filled in it sends a notification informing it to reset the password, follow the code below:
` def get_user(%Plug.Conn{} = conn) do with {:ok, {name, password}} <- fetch_credentials(conn), {_, %User{} = user} <- {:user, fetch_user(name)}, {:ok, user} <- check_password(user, password) do {:ok, user} else {:error, :invalid_password} = error -> case user.legacy_password do nil -> error _ -> conn |> put_flash(:warning, "legacy user. Reset your password.") |> redirect(to: Routes.user_edit_password_path(conn, :edit, user)) end error -> error end end
defp check_password(%User{} = user, password) do if AuthenticationPlug.checkpw(password, user.password_hash) do {:ok, user} else {:error, :invalid_password} end end `
when I apply this change and restart the plaroma it starts normally but the site gives the error "502 Bad Gateway", how do I make it analyze the bcrypt or the simplest thing would be to see if it has a legacy_password in the table and if it has send one notification?.
Remembering that I'm using a platform made in php and not mastodon