authtools 0.1.3 → 0.2.0
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/.gitignore +26 -0
- data/CHANGELOG +8 -1
- data/Rakefile +0 -1
- data/TODO +3 -0
- data/VERSION +1 -0
- data/authtools.gemspec +9 -4
- data/lib/authtools.rb +2 -0
- data/lib/authtools/common.rb +2 -2
- data/lib/authtools/password.rb +13 -14
- data/lib/authtools/token.rb +11 -8
- metadata +9 -4
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## Gemfile
|
2
|
+
*.gem
|
3
|
+
|
4
|
+
## MAC OS
|
5
|
+
.DS_Store
|
6
|
+
|
7
|
+
## TEXTMATE
|
8
|
+
*.tmproj
|
9
|
+
tmtags
|
10
|
+
|
11
|
+
## EMACS
|
12
|
+
*~
|
13
|
+
\#*
|
14
|
+
.\#*
|
15
|
+
|
16
|
+
## VIM
|
17
|
+
*.swp
|
18
|
+
|
19
|
+
## PROJECT::GENERAL
|
20
|
+
coverage
|
21
|
+
rdoc
|
22
|
+
pkg
|
23
|
+
|
24
|
+
## PROJECT::SPECIFIC
|
25
|
+
*.gem
|
26
|
+
doc
|
data/CHANGELOG
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
Authtools changelog.
|
2
2
|
|
3
|
-
v0.
|
3
|
+
v0.2.0 [4.07.2010]
|
4
|
+
* Improvements in implementation
|
5
|
+
* Minor bug fixes
|
6
|
+
* Added main file: lib/authtools.rb
|
7
|
+
* Added VERSION file
|
8
|
+
* Created TODO list
|
9
|
+
|
10
|
+
v0.1.0 [23.03.2010]
|
4
11
|
* Generating password hash
|
5
12
|
* Comparing password strings with stored hash
|
6
13
|
* Generating unique tokens
|
data/Rakefile
CHANGED
@@ -5,7 +5,6 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gemspec|
|
7
7
|
gemspec.name = "authtools"
|
8
|
-
gemspec.version = "0.1.3"
|
9
8
|
gemspec.summary = "Usefull staff for tokens, passwords and authorization"
|
10
9
|
gemspec.description = "Thanks to authtools you can easy generate salted password has
|
11
10
|
h or unique token and check if specified password string is valid for stored hash..."
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/authtools.gemspec
CHANGED
@@ -5,24 +5,29 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{authtools}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kris Kowalik"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-04}
|
13
13
|
s.description = %q{Thanks to authtools you can easy generate salted password has
|
14
14
|
h or unique token and check if specified password string is valid for stored hash...}
|
15
15
|
s.email = %q{kriss.kowalik@gmail.com}
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE",
|
18
|
-
"README.rdoc"
|
18
|
+
"README.rdoc",
|
19
|
+
"TODO"
|
19
20
|
]
|
20
21
|
s.files = [
|
21
|
-
"
|
22
|
+
".gitignore",
|
23
|
+
"CHANGELOG",
|
22
24
|
"LICENSE",
|
23
25
|
"README.rdoc",
|
24
26
|
"Rakefile",
|
27
|
+
"TODO",
|
28
|
+
"VERSION",
|
25
29
|
"authtools.gemspec",
|
30
|
+
"lib/authtools.rb",
|
26
31
|
"lib/authtools/common.rb",
|
27
32
|
"lib/authtools/password.rb",
|
28
33
|
"lib/authtools/token.rb"
|
data/lib/authtools.rb
ADDED
data/lib/authtools/common.rb
CHANGED
data/lib/authtools/password.rb
CHANGED
@@ -3,6 +3,9 @@ require 'authtools/common'
|
|
3
3
|
|
4
4
|
module Authtools
|
5
5
|
module Password
|
6
|
+
extend Common
|
7
|
+
extend self
|
8
|
+
|
6
9
|
# Generates a new salt and rehashes the password. Returns mixed hash.
|
7
10
|
#
|
8
11
|
# == Examples
|
@@ -12,10 +15,10 @@ module Authtools
|
|
12
15
|
# # 2a6c4fbcbe5d3944ccr1x6DlrfTf6OUrwl6ohoivxN2fAQiblav1sLyd9
|
13
16
|
# # z7PFaQgQH3XxTA0BuMAbFRmMM"
|
14
17
|
#
|
15
|
-
def
|
16
|
-
salt =
|
18
|
+
def generate(password)
|
19
|
+
salt = self.salt
|
17
20
|
hash = self.hash(password, salt)
|
18
|
-
|
21
|
+
store(hash, salt)
|
19
22
|
end
|
20
23
|
|
21
24
|
# Alias for generate method
|
@@ -31,9 +34,9 @@ module Authtools
|
|
31
34
|
# Authtools::Password.check('mysecret', store) # => true
|
32
35
|
# Authtools::Password.check('fake', store) # => false
|
33
36
|
#
|
34
|
-
def
|
35
|
-
hash =
|
36
|
-
salt =
|
37
|
+
def check(password, store)
|
38
|
+
hash = get_hash(store)
|
39
|
+
salt = get_salt(store)
|
37
40
|
if self.hash(password, salt) == hash
|
38
41
|
true
|
39
42
|
else
|
@@ -41,31 +44,27 @@ module Authtools
|
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
|
-
protected
|
45
|
-
|
46
|
-
include Authtools::Common
|
47
|
-
|
48
47
|
# Generates a 128 character hash.
|
49
48
|
#
|
50
|
-
def
|
49
|
+
def hash(password, salt)
|
51
50
|
Digest::SHA512.hexdigest("#{password}:#{salt}")
|
52
51
|
end
|
53
52
|
|
54
53
|
# Mixes the hash and salt together for storage.
|
55
54
|
#
|
56
|
-
def
|
55
|
+
def store(hash, salt)
|
57
56
|
hash + salt
|
58
57
|
end
|
59
58
|
|
60
59
|
# Gets the hash from a stored password.
|
61
60
|
#
|
62
|
-
def
|
61
|
+
def get_hash(store)
|
63
62
|
store[0..127]
|
64
63
|
end
|
65
64
|
|
66
65
|
# Gets the salt from a stored password.
|
67
66
|
#
|
68
|
-
def
|
67
|
+
def get_salt(store)
|
69
68
|
store[128..192]
|
70
69
|
end
|
71
70
|
end
|
data/lib/authtools/token.rb
CHANGED
@@ -3,15 +3,18 @@ require 'authtools/common'
|
|
3
3
|
|
4
4
|
module Authtools
|
5
5
|
module Token
|
6
|
+
extend Common
|
7
|
+
extend self
|
8
|
+
|
6
9
|
SHORT = 256
|
7
10
|
MEDIUM = 384
|
8
11
|
LONG = 512
|
9
12
|
|
10
13
|
# Generates new token with specified size.
|
11
14
|
#
|
12
|
-
def
|
15
|
+
def generate(size=SHORT)
|
13
16
|
hash = Digest::SHA2.new(size)
|
14
|
-
hash <<
|
17
|
+
hash << self.salt
|
15
18
|
hash.to_s
|
16
19
|
end
|
17
20
|
|
@@ -23,20 +26,20 @@ module Authtools
|
|
23
26
|
|
24
27
|
# Shortcut for generate 256 bit token.
|
25
28
|
#
|
26
|
-
def
|
27
|
-
|
29
|
+
def short
|
30
|
+
generate(SHORT)
|
28
31
|
end
|
29
32
|
|
30
33
|
# Shortcut for generate 384 bit token.
|
31
34
|
#
|
32
|
-
def
|
33
|
-
|
35
|
+
def medium
|
36
|
+
generate(MEDIUM)
|
34
37
|
end
|
35
38
|
|
36
39
|
# Shortcut for generate 512 bit token.
|
37
40
|
#
|
38
|
-
def
|
39
|
-
|
41
|
+
def long
|
42
|
+
generate(LONG)
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kris Kowalik
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-08-04 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -29,12 +29,17 @@ extensions: []
|
|
29
29
|
extra_rdoc_files:
|
30
30
|
- LICENSE
|
31
31
|
- README.rdoc
|
32
|
+
- TODO
|
32
33
|
files:
|
34
|
+
- .gitignore
|
33
35
|
- CHANGELOG
|
34
36
|
- LICENSE
|
35
37
|
- README.rdoc
|
36
38
|
- Rakefile
|
39
|
+
- TODO
|
40
|
+
- VERSION
|
37
41
|
- authtools.gemspec
|
42
|
+
- lib/authtools.rb
|
38
43
|
- lib/authtools/common.rb
|
39
44
|
- lib/authtools/password.rb
|
40
45
|
- lib/authtools/token.rb
|