authtools 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.1 [23.03.2010]
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/TODO ADDED
@@ -0,0 +1,3 @@
1
+ TODO list:
2
+
3
+ * Write specs!
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -5,24 +5,29 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{authtools}
8
- s.version = "0.1.3"
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-03-23}
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
- "CHANGELOG",
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"
@@ -0,0 +1,2 @@
1
+ require 'authtools/token'
2
+ require 'authtools/password'
@@ -2,10 +2,10 @@ module Authtools
2
2
  module Common
3
3
  # Generates a psuedo-random 64 character string.
4
4
  #
5
- def self.salt
5
+ def salt
6
6
  salt = ""
7
7
  64.times { salt << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
8
8
  salt
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -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 self.generate(password)
16
- salt = Authtools::Common.salt
18
+ def generate(password)
19
+ salt = self.salt
17
20
  hash = self.hash(password, salt)
18
- self.store(hash, salt)
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 self.check(password, store)
35
- hash = self.get_hash(store)
36
- salt = self.get_salt(store)
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 self.hash(password, salt)
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 self.store(hash, salt)
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 self.get_hash(store)
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 self.get_salt(store)
67
+ def get_salt(store)
69
68
  store[128..192]
70
69
  end
71
70
  end
@@ -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 self.generate(size=SHORT)
15
+ def generate(size=SHORT)
13
16
  hash = Digest::SHA2.new(size)
14
- hash << Authtools::Common.salt
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 self.short
27
- self.generate(SHORT)
29
+ def short
30
+ generate(SHORT)
28
31
  end
29
32
 
30
33
  # Shortcut for generate 384 bit token.
31
34
  #
32
- def self.medium
33
- self.generate(MEDIUM)
35
+ def medium
36
+ generate(MEDIUM)
34
37
  end
35
38
 
36
39
  # Shortcut for generate 512 bit token.
37
40
  #
38
- def self.long
39
- self.generate(LONG)
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
- - 1
8
- - 3
9
- version: 0.1.3
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-03-23 00:00:00 +01:00
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