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.Captcha.Native do
6 import Pleroma.Web.Gettext
7 alias Pleroma.Captcha.Service
14 %{error: dgettext("errors", "Captcha timeout")}
16 {:ok, answer_data, img_binary} ->
20 url: "data:image/png;base64," <> Base.encode64(img_binary),
21 answer_data: answer_data
27 def validate(_token, captcha, captcha) when not is_nil(captcha), do: :ok
28 def validate(_token, _captcha, _answer), do: {:error, dgettext("errors", "Invalid CAPTCHA")}
32 |> :crypto.strong_rand_bytes()
33 |> Base.url_encode64(padding: false)