PwnedCheck 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +38 -2
- data/lib/pwnedcheck.rb +39 -19
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7fee764c27afccf572fbe7e102af145f448732cd
|
|
4
|
+
data.tar.gz: 5c4b8aa0868685acd45b0586f3cc1c45e0c5d755
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 223e1a0a7ac286108af5245cd243d854a6ec26c90cc57ae0051a1c147d1da3882e558e97ffe595d8c5ddc0cd4389da6fb749aad8549c7974ec4d0db86b9d225f
|
|
7
|
+
data.tar.gz: fb2fc25b85e8ffa0dd623ead83d61f41c4a52499c8645f890e5e355e082c11632e0440a79a37628cb0c1ad0f9f1ac0aaced5df47cc0a13a3898ebbe4bb10a65b
|
data/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# PwnedCheck
|
|
2
|
+
[](http://badge.fury.io/rb/PwnedCheck)
|
|
2
3
|
|
|
3
4
|
Ruby gem to check to see if an email address, phone number, or username is on http://haveibeenpwned.com
|
|
4
5
|
|
|
5
6
|
<table>
|
|
6
7
|
<tr>
|
|
7
8
|
<th>Version</th>
|
|
8
|
-
<td>1.0.
|
|
9
|
+
<td>1.0.18</td>
|
|
9
10
|
</tr>
|
|
10
11
|
<tr>
|
|
11
12
|
<th>Author</th>
|
|
@@ -45,7 +46,42 @@ list.each do |item|
|
|
|
45
46
|
puts "#{item} --> Not found on http://haveibeenpwned.com"
|
|
46
47
|
else
|
|
47
48
|
sites.each do |site|
|
|
48
|
-
|
|
49
|
+
#site is a hash of data returned
|
|
50
|
+
puts item
|
|
51
|
+
puts "\tTitle=#{site['Title']}"
|
|
52
|
+
puts "\tBreach Date=#{site['BreachDate']}"
|
|
53
|
+
puts "\tDescription=#{site['Description']}"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
rescue PwnedCheck::InvalidEmail => e
|
|
57
|
+
puts "#{item} --> #{e.message}"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
````
|
|
61
|
+
|
|
62
|
+
`````ruby
|
|
63
|
+
require 'pwnedcheck'
|
|
64
|
+
|
|
65
|
+
# The 4 cases to check for pastes.
|
|
66
|
+
# foo@bar.com is a valid address on the site
|
|
67
|
+
# foo232323ce23ewd@bar.com is a valid address, but not on the site
|
|
68
|
+
# foo.bar.com is an invalid format
|
|
69
|
+
# mralexgray is a user id in snapchat
|
|
70
|
+
list = ['foo@bar.com', 'foo232323ce23ewd@bar.com', 'foo.bar.com', 'mralexgray']
|
|
71
|
+
|
|
72
|
+
list.each do |item|
|
|
73
|
+
begin
|
|
74
|
+
sites = PwnedCheck::check_pastes(item)
|
|
75
|
+
if sites.length == 0
|
|
76
|
+
puts "#{item} --> Not found on http://haveibeenpwned.com"
|
|
77
|
+
else
|
|
78
|
+
sites.each do |site|
|
|
79
|
+
#site is a hash of data returned
|
|
80
|
+
puts item
|
|
81
|
+
puts "\tSource=#{site['Source']}"
|
|
82
|
+
puts "\tTitle=#{site['Title']}"
|
|
83
|
+
puts "\tDate=#{site['Date']}"
|
|
84
|
+
puts "\tEmail Count=#{site['EmailCount']}"
|
|
49
85
|
end
|
|
50
86
|
end
|
|
51
87
|
rescue PwnedCheck::InvalidEmail => e
|
data/lib/pwnedcheck.rb
CHANGED
|
@@ -33,21 +33,35 @@ module PwnedCheck
|
|
|
33
33
|
super 'Invalid email address format'
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
+
|
|
37
|
+
class RequestThrottled < Exception
|
|
38
|
+
attr_accessor :timeout
|
|
39
|
+
def initialize (t)
|
|
40
|
+
@timeout = t.to_i
|
|
41
|
+
end
|
|
42
|
+
end
|
|
36
43
|
|
|
37
44
|
# Check an address against http://haveibeenpwned.com
|
|
38
45
|
#
|
|
39
46
|
# @param item [String] the item to check. Could be an email address, phone number, or username
|
|
40
47
|
# @return [Array] an array of sites that the email address is associated with
|
|
41
48
|
def self.check(item)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
begin
|
|
50
|
+
uri = URI.parse "https://haveibeenpwned.com/api/v2/breachedaccount/#{CGI::escape(item)}"
|
|
51
|
+
response = Net::HTTP.get_response uri
|
|
52
|
+
case response.code
|
|
53
|
+
when '200'
|
|
54
|
+
JSON.parse response.body
|
|
55
|
+
when '404'
|
|
56
|
+
[]
|
|
57
|
+
when '400'
|
|
58
|
+
fail InvalidEmail
|
|
59
|
+
when '429'
|
|
60
|
+
raise RequestThrottled.new response.header['Retry-After']
|
|
61
|
+
end
|
|
62
|
+
rescue RequestThrottled => err
|
|
63
|
+
sleep err.timeout
|
|
64
|
+
retry
|
|
51
65
|
end
|
|
52
66
|
end
|
|
53
67
|
|
|
@@ -56,16 +70,22 @@ module PwnedCheck
|
|
|
56
70
|
# @param item [String] the item to check. Could be an email address, phone number, or username
|
|
57
71
|
# @return [Array] an array of pastes that the email address is associated with
|
|
58
72
|
def self.check_pastes(item)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
begin
|
|
74
|
+
uri = URI.parse "https://haveibeenpwned.com/api/v2/pasteaccount/#{CGI::escape(item)}"
|
|
75
|
+
response = Net::HTTP.get_response uri
|
|
76
|
+
case response.code
|
|
77
|
+
when '200'
|
|
78
|
+
JSON.parse response.body
|
|
79
|
+
when '404'
|
|
80
|
+
[]
|
|
81
|
+
when '400'
|
|
82
|
+
fail InvalidEmail
|
|
83
|
+
when '429'
|
|
84
|
+
raise RequestThrottled.new response.header['Retry-After']
|
|
85
|
+
end
|
|
86
|
+
rescue RequestThrottled => err
|
|
87
|
+
sleep err.timeout
|
|
88
|
+
retry
|
|
68
89
|
end
|
|
69
90
|
end
|
|
70
|
-
|
|
71
91
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: PwnedCheck
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.19
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Carl Sampson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-10-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Checks an email address against haveibeenpwned.com.
|
|
14
14
|
email: chs@chs.us
|
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
44
44
|
version: '0'
|
|
45
45
|
requirements: []
|
|
46
46
|
rubyforge_project:
|
|
47
|
-
rubygems_version: 2.
|
|
47
|
+
rubygems_version: 2.6.8
|
|
48
48
|
signing_key:
|
|
49
49
|
specification_version: 4
|
|
50
50
|
summary: Checks an email address against haveibeenpwned.com.
|