pwned_passwords_v2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52b4f2c805586834cfe604aab21a0348fea65939
4
+ data.tar.gz: f76c44bb713b503d9f061027eabd4a9e609a6dc9
5
+ SHA512:
6
+ metadata.gz: 61771e9114ff76de3e25d14e0d26711bf89cd28b765d8430ac5d84585b0c4593ca71259e027183c4d1289f843d06b133bc5d39e2b708fa9159ff4e66ae4eca6c
7
+ data.tar.gz: 29141f555768e042d8afbe85a31924a39dd2ec5d897216366c0df0df136d6fb9c9d0d9703141077a2ac3c68263cf8df1b98deb60c80cae2e105a18c903c5e8b6
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pwned_passwords_v2.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Dan Singerman
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.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # PwnedPasswordsV2
2
+
3
+ This gem is a simple wrapper to Troy Hunt's https://api.pwnedpasswords.com service to check if a password has been found in a data breach.
4
+
5
+ See https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2/ for more details.
6
+
7
+ ## Note
8
+
9
+ The code is kept deliberately simple so you can eyeball what is going on.
10
+
11
+ The passwords you use in this gem do not get sent externally. The password is sha1 hashed, and then only the first 5 characters are sent externally.
12
+
13
+ Troy Hunt's [blog post](https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2/) explains this process in more detail.
14
+
15
+ If you like this gem please donate to Troy's [donations page](https://haveibeenpwned.com/Donate)
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'pwned_passwords_v2'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install pwned_passwords_v2
32
+
33
+ ## Usage
34
+
35
+ You can find out the number of times a password has appeared in Troy Hunt's Pwned Passwords V2 dataset as follows.
36
+
37
+ ``` > PwnedPasswordsV2.have_i?('password')
38
+ => 3303003
39
+ > PwnedPasswordsV2.have_i?('a_nice_strong_password+%^&*()__*')
40
+ => 0
41
+ ```
42
+
43
+ 2.0.0-p643 :007 >
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dansingerman/pwned_passwords_v2.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
58
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pwned_passwords_v2"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module PwnedPasswordsV2
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ require "pwned_passwords_v2/version"
2
+ require "digest"
3
+ require "open-uri"
4
+
5
+ module PwnedPasswordsV2
6
+ def self.have_i?(password)
7
+ sha1_hash = Digest::SHA1.hexdigest(password).upcase
8
+ sha1_hash_prefix = sha1_hash[0..4]
9
+
10
+ response = open("https://api.pwnedpasswords.com/range/#{sha1_hash_prefix}").read
11
+
12
+ sha1_hash_prefix_matches = response.split(/\r?\n/)
13
+
14
+ if sha1_hash_prefix_matches.size == 0
15
+ raise "No sha1 prefix matches returned from https://api.pwnedpasswords.com. The service is probably broken."
16
+ end
17
+
18
+ sha1_hash_prefix_matches.each_with_index do |sha1_hash_prefix_match, line|
19
+ unless sha1_hash_prefix_match.strip[/\b[0-9A-F]{35}:[0-9]+$\b/]
20
+ raise "Unexpected response format in line #{line + 1} - #{sha1_hash_prefix_match}"
21
+ end
22
+
23
+ sha1_hash_suffix = sha1_hash_prefix_match.split(':')[0]
24
+
25
+ return sha1_hash_prefix_match.split(':')[1].to_i if "#{sha1_hash_prefix}#{sha1_hash_suffix}" == sha1_hash
26
+ end
27
+
28
+ return 0
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pwned_passwords_v2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pwned_passwords_v2"
8
+ spec.version = PwnedPasswordsV2::VERSION
9
+ spec.authors = ["Dan Singerman"]
10
+ spec.email = ["dan@reasonfactory.com"]
11
+
12
+ spec.summary = "Wrapper for Troy Hunt's api.pwnedpasswords.com service"
13
+ spec.description = "Uses api.pwnedpasswords.com to identify if a password has been pwned, but only sends the first 5 characters of the SHA1 hash"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pwned_passwords_v2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Singerman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-22 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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
+ description: Uses api.pwnedpasswords.com to identify if a password has been pwned,
42
+ but only sends the first 5 characters of the SHA1 hash
43
+ email:
44
+ - dan@reasonfactory.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - .travis.yml
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/pwned_passwords_v2.rb
58
+ - lib/pwned_passwords_v2/version.rb
59
+ - pwned_passwords_v2.gemspec
60
+ homepage:
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.8
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Wrapper for Troy Hunt's api.pwnedpasswords.com service
84
+ test_files: []