hashpasswd 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.
- data/lib/hashpasswd.rb +50 -0
- metadata +47 -0
data/lib/hashpasswd.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Hashpasswd
|
2
|
+
VERSION = '0.1.0'
|
3
|
+
HASH_SECTIONS = 4
|
4
|
+
ITERATIONS_INDEX = 1
|
5
|
+
SALT_INDEX = 2
|
6
|
+
HASH_INDEX = 3
|
7
|
+
|
8
|
+
require 'securerandom'
|
9
|
+
require 'base64'
|
10
|
+
|
11
|
+
def self.version()
|
12
|
+
return VERSION
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.createhash(password, options={})
|
16
|
+
@pbkdf2_iterations = options[:pbkdf2_iterations] || 2000
|
17
|
+
@salt_byte_size = options[:salt_byte_size] ||24
|
18
|
+
@hash_byte_size = options[:hash_byte_size]|| 24
|
19
|
+
@delimeter = options[:delimter] || ':'
|
20
|
+
@digest = options[:digest] || 'SHA1'
|
21
|
+
|
22
|
+
salt = SecureRandom.base64( @salt_byte_size )
|
23
|
+
pbkdf2 = OpenSSL::PKCS5::pbkdf2_hmac(
|
24
|
+
password,
|
25
|
+
salt,
|
26
|
+
@pbkdf2_iterations,
|
27
|
+
@hash_byte_size,
|
28
|
+
@digest
|
29
|
+
)
|
30
|
+
return [@digest, @pbkdf2_iterations, salt, Base64.encode64( pbkdf2 )].join( @delimeter )
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.validatepasswd(password, hash, options={})
|
34
|
+
@delimeter = options[:delimter] || ':'
|
35
|
+
|
36
|
+
params = hash.split(@delimeter)
|
37
|
+
return false if params.length != HASH_SECTIONS
|
38
|
+
|
39
|
+
pbkdf2 = Base64.decode64( params[HASH_INDEX] )
|
40
|
+
testhash = OpenSSL::PKCS5::pbkdf2_hmac(
|
41
|
+
password,
|
42
|
+
params[SALT_INDEX],
|
43
|
+
params[ITERATIONS_INDEX].to_i,
|
44
|
+
pbkdf2.length,
|
45
|
+
params[0]
|
46
|
+
)
|
47
|
+
|
48
|
+
return pbkdf2 == testhash
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hashpasswd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Tuttle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Password hashing and validation using OpenSSL::PKCS5::pbkdf2_hmac for
|
15
|
+
the hash and SecureRandom.base64 for the salt. Digest defaults to SHA1, but can
|
16
|
+
be set to any digest (eg SHA256) supported by your systems OpenSSL lib.
|
17
|
+
email: bentuttle.du@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/hashpasswd.rb
|
23
|
+
homepage: http://rubygems.org/gems/hashpasswd
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.10
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Password hashing and validation
|
47
|
+
test_files: []
|