1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Captcha.Kocaptcha do
6 alias Pleroma.Captcha.Service
11 endpoint = Pleroma.Config.get!([__MODULE__, :endpoint])
13 case Pleroma.HTTP.get(endpoint <> "/new") do
15 %{error: :kocaptcha_service_unavailable}
18 json_resp = Jason.decode!(res.body)
22 token: json_resp["token"],
23 url: endpoint <> json_resp["url"],
24 answer_data: json_resp["md5"],
25 seconds_valid: Pleroma.Config.get([Pleroma.Captcha, :seconds_valid])
31 def validate(_token, captcha, answer_data) do
32 # Here the token is unsed, because the unencrypted captcha answer is just passed to method
33 if not is_nil(captcha) and
34 :crypto.hash(:md5, captcha) |> Base.encode16() == String.upcase(answer_data),
36 else: {:error, :invalid}