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 [breachedaccount](https://haveibeenpwned.com/API/v3#BreachesForAccount) API v3.
"""
@doc """
Reduces the list of flattened emails returned from the
`EmailFlattener.flatten/1` call, and returns the
integer sum.
This sum indicates the number of times a given email has
appeared in data breaches from the [breachedaccount](https://haveibeenpwned.com/API/v3#BreachesForAccount)
service.
## Example
iex> reduce_email_list(email_list)
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