hibp_check 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b8ba3c79b7ed520b70207d01e5b72f9c2c60b0b7b299a2a4acb4408e98d175e8
4
+ data.tar.gz: b0f7e5beea10918568285237097c840b079db12b38baa5f8fa6940a1a84fb586
5
+ SHA512:
6
+ metadata.gz: 3a23e3173e12a5a89e0b8e96935dc6588e63f8fb48f6bd28066abaaa7c938bf89891a1db51e4c729b2a1efcc9bea56f5518cf846befdc086dfd2e7a79fff015a
7
+ data.tar.gz: 0061c40d8646e2891270cf6f5fe2b4dc4f1e99694b32b7c8822301409dc989a03b28a65118f0af2bb25d9ba27b2a63cc43c031a4737b294d123239d94f5b3aec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 John Ash
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "hibp_check/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hibp_check"
7
+ spec.version = HibpCheck::VERSION
8
+ spec.authors = ["John Ash"]
9
+ spec.email = ["john.ash@k3integrations.com"]
10
+
11
+ spec.summary = %q{Check passwords against API of compromised passwords}
12
+ spec.description = %q{Check passwords against API of compromised passwords}
13
+ spec.homepage = "https://github.com/k3integrations/hibp_check"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ [
20
+ 'LICENSE.txt',
21
+ 'hibp_check.gemspec',
22
+ 'lib/hibp_check.rb',
23
+ 'lib/hibp_check/version.rb'
24
+ ]
25
+ end
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ spec.add_development_dependency "vcr", "~> 4.0"
32
+ spec.add_development_dependency "webmock", "~> 3.5"
33
+ end
data/lib/hibp_check.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'resolv-replace' # Use better DNS resolver
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'digest'
5
+
6
+ class HibpCheck
7
+ API_URL = 'https://api.pwnedpasswords.com/range/'
8
+
9
+ attr_reader :prefix, :remainder, :hashes, :params, :request, :response
10
+
11
+ def initialize(params={})
12
+ @params = params
13
+ end
14
+
15
+ def password_used(password)
16
+ return nil if password.nil?
17
+ sha1_used Digest::SHA1.hexdigest(password.to_s)
18
+ end
19
+
20
+ def sha1_used(hashed)
21
+ return nil unless hashed =~ /^[0-9a-f]{40}$/i
22
+ @prefix = hashed.slice(0..4).upcase
23
+ @remainder = hashed.slice(5..-1).upcase
24
+ @hashes = fetch_hashes_by_prefix prefix
25
+ if hashes
26
+ return $1.to_i if hashes.match(/#{remainder}:(\d+)/)
27
+ return 0
28
+ end
29
+ nil
30
+ end
31
+
32
+ private
33
+
34
+ def fetch_hashes_by_prefix(prefix)
35
+ fetch "#{API_URL}#{prefix}"
36
+ return response.body if response.code == "200"
37
+ nil
38
+ end
39
+
40
+ def fetch(url)
41
+ uri = URI(url)
42
+
43
+ Net::HTTP.start(uri.host, uri.port, params.merge(use_ssl: uri.scheme=='https')) do |http|
44
+ @request = Net::HTTP::Get.new uri
45
+
46
+ @response = http.request @request # Net::HTTPResponse object
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ class HibpCheck
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hibp_check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - John Ash
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ description: Check passwords against API of compromised passwords
84
+ email:
85
+ - john.ash@k3integrations.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE.txt
91
+ - hibp_check.gemspec
92
+ - lib/hibp_check.rb
93
+ - lib/hibp_check/version.rb
94
+ homepage: https://github.com/k3integrations/hibp_check
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.7.7
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Check passwords against API of compromised passwords
118
+ test_files: []