Module: PwnedCheck

Defined in:
lib/pwnedcheck.rb

Overview

PwnedCheck module

Defined Under Namespace

Classes: InvalidEmail

Class Method Summary collapse

Class Method Details

.check(item) ⇒ Array

Check an address against haveibeenpwned.com

Parameters:

  • item (String)

    the item to check. Could be an email address, phone number, or username

Returns:

  • (Array)

    an array of sites that the email address is associated with



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pwnedcheck.rb', line 41

def self.check(item)
  uri = URI.parse "https://haveibeenpwned.com/api/breachedaccount/#{CGI::escape(item)}"
  response = Net::HTTP.get_response uri
  case response.code
  when '200'
    JSON.parse response.body
  when '404'
    []
  when '400'
    fail InvalidEmail
  end
end