hashpasswd 0.1.1 → 0.1.2
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 +17 -5
- metadata +2 -1
data/lib/hashpasswd.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Hashpasswd
|
2
|
-
VERSION = '0.1.0'
|
3
2
|
HASH_SECTIONS = 4
|
4
3
|
ITERATIONS_INDEX = 1
|
5
4
|
SALT_INDEX = 2
|
@@ -8,10 +7,16 @@ module Hashpasswd
|
|
8
7
|
require 'securerandom'
|
9
8
|
require 'base64'
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
# Creates a hash from a plain text password
|
11
|
+
# @param password [String] A plain text password
|
12
|
+
# @param [Hash{Symbol => String, Number}] options
|
13
|
+
# @option options [Int] :pbkdf2_iterations (2000) The PBKDF2 iteration count
|
14
|
+
# @option options [Int] :salt_byte_size (24) The byte size for the salt
|
15
|
+
# @option options [Int] :hash_byte_size (24) The byte size for the hash
|
16
|
+
# @option options [String] :delimiter (':') The delimeter for the hash string, changing the delimiter is not recommended as you will have to remember it and supply it as an option to validatepasswd()
|
17
|
+
# @option options [String] :digest ('SHA1') The digest, can be any digest supported by OpenSSL on your sytem (eg 'SHA224', 'SHA256', 'SHA384' or 'SHA512')
|
18
|
+
# @return [String] the hash as "<digest>:<pbkdf2_iterations>:<salt>:<hash>"
|
19
|
+
#
|
15
20
|
def self.createhash(password, options={})
|
16
21
|
@pbkdf2_iterations = options[:pbkdf2_iterations] || 2000
|
17
22
|
@salt_byte_size = options[:salt_byte_size] ||24
|
@@ -30,6 +35,13 @@ module Hashpasswd
|
|
30
35
|
return [@digest, @pbkdf2_iterations, salt, Base64.encode64( pbkdf2 )].join( @delimeter )
|
31
36
|
end
|
32
37
|
|
38
|
+
# Validates a password against a hash
|
39
|
+
# @param password [String] A plain text password
|
40
|
+
# @param hash [String] "<digest>:<pbkdf2_iterations>:<salt>:<hash>"
|
41
|
+
# @param [Hash{Symbol => String}] options
|
42
|
+
# @option options [String] :delimiter (':') The delimeter for the hash string, only necessary if you did not use the default delimiter (':') when creating the hash.
|
43
|
+
# @return [Boolean] True if the password matches the hash; False if not.
|
44
|
+
#
|
33
45
|
def self.validatepasswd(password, hash, options={})
|
34
46
|
@delimeter = options[:delimter] || ':'
|
35
47
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashpasswd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -45,3 +45,4 @@ signing_key:
|
|
45
45
|
specification_version: 3
|
46
46
|
summary: Password hashing and validation
|
47
47
|
test_files: []
|
48
|
+
has_rdoc:
|