Packages

A simple application to check if an email or password has been pwned using the HaveIBeenPwned? API. It requires a purchased hibp-api-key in order to use the email checking functions.

Current section

Files

Jump to
pwned_coretheory lib utils email_reducer.ex
Raw

lib/utils/email_reducer.ex

defmodule Pwned.Utils.EmailReducer do
@moduledoc """
Functions for reducing the email list returned
from the [breachedacocunt](https://haveibeenpwned.com/API/v3#BreachesForAccount) API v3.
"""
@doc """
Reduces an email list and returns the integer sum.
## Example
iex> reduce_email_list(email_list)
iex>
iex> 4893554722
"""
def reduce_email_list(email_list) do
email_list
|> to_string()
|> String.replace("\"PwnCount\"", "")
|> String.split(":", trim: true)
|> Stream.map(fn count -> String.to_integer(count) end)
|> Enum.reduce(fn count, acc -> count + acc end)
end
end