Packages

Wrapper around Troy Hunt's endpoints for checking whether a given password has been leaked in any of his HaveIBeenPwned datasets. This wrapper uses the 'safe' endpoints by first calculating the SHA1 and then only POSTing the first 5 characters to the API endpoints.

Current section

Files

Jump to
leaked_passwords lib have_i_been_pwned_api range.ex
Raw

lib/have_i_been_pwned_api/range.ex

defmodule HaveIBeenPwnedApi.Range do
@default_adapter HaveIBeenPwnedApi.Adapter
def get(<<hash_prefix::bytes-size(5)>>) do
adapter().request(:get, "/range/" <> String.upcase(hash_prefix))
end
def get!(<<hash_prefix::bytes-size(5)>>) do
adapter().request!(:get, "/range/" <> String.upcase(hash_prefix))
end
defp adapter, do: Application.get_env(:leaked_passwords, :adapter) || @default_adapter
end