password_hasher 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: d3d5200addbaa0173c61dab01de421250330c593
4
+ data.tar.gz: c8d79498f1443ba21a2d61ea3d54aff93bb82385
5
+ SHA512:
6
+ metadata.gz: 6317d71b0725f651b1f185de847c4ebee7a1e84692d314d809fb481caf8756dcf38cea23ae3d5b7aa829549b29a8713c5909d593181bb3f057d573f259a76ea6
7
+ data.tar.gz: 49ab646da21b4949df30797646d4bbdccae9955e4cd606caacbf5831368e421bd8c73fa9b68a9c327a71ee46a3b47589057d06060f41351262e4b37409e739f0
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,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in password_hasher.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 riggleg
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,48 @@
1
+
2
+ ## Installation
3
+
4
+ Add this line to your application's Gemfile:
5
+
6
+ ```ruby
7
+ gem 'password_hasher'
8
+ ```
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install password_hasher
17
+
18
+ ## Usage
19
+
20
+
21
+
22
+ ## Development
23
+
24
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
25
+
26
+ 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).
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/password_hasher.
31
+
32
+
33
+ ## License
34
+
35
+ Password Hashing With PBKDF2 (http://crackstation.net/hashing-security.htm).
36
+ Copyright (c) 2013, Taylor Hornby
37
+ All rights reserved.
38
+
39
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
40
+
41
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
42
+
43
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
44
+ and/or other materials provided with the distribution.
45
+
46
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
+
48
+
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 "password_hasher"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module PasswordHasher
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,84 @@
1
+ require "password_hasher/version"
2
+ require 'securerandom'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ module PasswordHasher
7
+
8
+ # The following constants can be changed without breaking existing hashes.
9
+ PBKDF2_ITERATIONS = 1000
10
+ SALT_BYTE_SIZE = 24
11
+ HASH_BYTE_SIZE = 24
12
+
13
+ HASH_SECTIONS = 4
14
+ SECTION_DELIMITER = ':'
15
+ ITERATIONS_INDEX = 1
16
+ SALT_INDEX = 2
17
+ HASH_INDEX = 3
18
+ # Returns a salted PBKDF2 hash of the password.
19
+ def self.createHash( password )
20
+ salt = SecureRandom.base64( SALT_BYTE_SIZE )
21
+ pbkdf2 = OpenSSL::PKCS5::pbkdf2_hmac_sha1(
22
+ password,
23
+ salt,
24
+ PBKDF2_ITERATIONS,
25
+ HASH_BYTE_SIZE
26
+ )
27
+ return ["sha1", PBKDF2_ITERATIONS, salt, Base64.encode64( pbkdf2 )].join( SECTION_DELIMITER )
28
+ end
29
+
30
+ # Checks if a password is correct given a hash of the correct one.
31
+ # correctHash must be a hash string generated with createHash.
32
+ def self.validatePassword( password, correctHash )
33
+ params = correctHash.split( SECTION_DELIMITER )
34
+ return false if params.length != HASH_SECTIONS
35
+
36
+ pbkdf2 = Base64.decode64( params[HASH_INDEX] )
37
+ testHash = OpenSSL::PKCS5::pbkdf2_hmac_sha1(
38
+ password,
39
+ params[SALT_INDEX],
40
+ params[ITERATIONS_INDEX].to_i,
41
+ pbkdf2.length
42
+ )
43
+
44
+ return pbkdf2 == testHash
45
+ end
46
+
47
+ def self.runSelfTests
48
+ puts "Sample hashes:"
49
+ 3.times { puts createHash("password") }
50
+
51
+ puts "\nRunning self tests..."
52
+ @@allPass = true
53
+
54
+ correctPassword = 'aaaaaaaaaa'
55
+ wrongPassword = 'aaaaaaaaab'
56
+ hash = createHash(correctPassword)
57
+
58
+ assert( validatePassword( correctPassword, hash ) == true, "correct password" )
59
+ assert( validatePassword( wrongPassword, hash ) == false, "wrong password" )
60
+
61
+ h1 = hash.split( SECTION_DELIMITER )
62
+ h2 = createHash( correctPassword ).split( SECTION_DELIMITER )
63
+ assert( h1[HASH_INDEX] != h2[HASH_INDEX], "different hashes" )
64
+ assert( h1[SALT_INDEX] != h2[SALT_INDEX], "different salt" )
65
+
66
+ if @@allPass
67
+ puts "*** ALL TESTS PASS ***"
68
+ else
69
+ puts "*** FAILURES ***"
70
+ end
71
+
72
+ return @@allPass
73
+ end
74
+
75
+ def self.assert( truth, msg )
76
+ if truth
77
+ puts "PASS [#{msg}]"
78
+ else
79
+ puts "FAIL [#{msg}]"
80
+ @@allPass = false
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'password_hasher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "password_hasher"
8
+ spec.version = PasswordHasher::VERSION
9
+ spec.authors = ["Taylor Hornby"]
10
+ spec.email = ["havoc AT defuse.ca "]
11
+
12
+ spec.summary = %q{Simple password hashing library.}
13
+ spec.description = %q{This gem was made from a preexisting library. I did not write the code. I just made it a gem so I could share it between projects.}
14
+ spec.homepage = "https://crackstation.net/hashing-security.htm"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: password_hasher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Taylor Hornby
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-04 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: This gem was made from a preexisting library. I did not write the code. I
42
+ just made it a gem so I could share it between projects.
43
+ email:
44
+ - 'havoc AT defuse.ca '
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/password_hasher.rb
58
+ - lib/password_hasher/version.rb
59
+ - password_hasher.gemspec
60
+ homepage: https://crackstation.net/hashing-security.htm
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.6
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Simple password hashing library.
84
+ test_files: []