passwd 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Passwd
2
2
 
3
+ [![Build Status](https://travis-ci.org/i2bskn/passwd.png?branch=master)](https://travis-ci.org/i2bskn/passwd)
4
+
3
5
  Password utility
4
6
 
5
7
  ## Installation
@@ -68,7 +70,7 @@ Passwd object:
68
70
  Default password is randomly generated.
69
71
  Default salt is "#{Time.now.to_s}".
70
72
 
71
- password = Passwd.new
73
+ password = Passwd::Password.new
72
74
  password.text # return text password.
73
75
  password.salt_text # return text salt.
74
76
  password.salt_hash # return hash salt.
@@ -81,10 +83,10 @@ Options that can be specified:
81
83
 
82
84
  Password authenticate:
83
85
 
84
- password = Passwd.new
86
+ password = Passwd::Password.new
85
87
  Passwd.auth(password.text, password.salt_hash, password.hash) # => true
86
88
  Passwd.auth("invalid!!", password.salt_hash, password.hash) # => false
87
-
89
+
88
90
  password == password.text # => true
89
91
  password == "invalid!!" # => false
90
92
 
data/Rakefile CHANGED
@@ -3,6 +3,8 @@ require "bundler/gem_tasks"
3
3
  Bundler.setup
4
4
  require 'rspec/core/rake_task'
5
5
 
6
+ task default: [:spec]
7
+
6
8
  desc "run spec"
7
9
  RSpec::Core::RakeTask.new(:spec) do |t|
8
10
  t.rspec_opts = ["-c", "-fs"]
data/lib/passwd.rb CHANGED
@@ -3,8 +3,7 @@
3
3
  require "passwd/version"
4
4
  require "digest/sha1"
5
5
 
6
- class Passwd
7
- attr_reader :text, :hash, :salt_text, :salt_hash
6
+ module Passwd
8
7
  @@config = {
9
8
  length: 8,
10
9
  lower: true,
@@ -24,54 +23,46 @@ class Passwd
24
23
  require_number: true
25
24
  }
26
25
 
27
- def initialize(options={password: nil, salt_text: Time.now.to_s})
28
- if options[:password].nil?
29
- # Create letters
30
- letters = Array.new
31
- letters += @@config[:letters_lower] if @@config[:lower]
32
- letters += @@config[:letters_upper] if @@config[:upper]
33
- letters += @@config[:letters_number] if @@config[:number]
26
+ class Password
27
+ attr_reader :text, :hash, :salt_text, :salt_hash
34
28
 
35
- # Create random password
36
- @text = Array.new(@@config[:length]){letters[rand(letters.size)]}.join
37
- else
38
- @text = options[:password]
29
+ def initialize(options={password: nil, salt_text: Time.now.to_s})
30
+ @text = options[:password].nil? ? Passwd.create : options[:password]
31
+ @salt_text = options[:salt_text] || Time.now.to_s
32
+ @salt_hash = Passwd.hashing(@salt_text)
33
+ @hash = Passwd.hashing("#{@salt_hash}#{@text}")
39
34
  end
40
- # @text = password.nil? ? self.class.create : password
41
- @salt_text = options[:salt_text] || Time.now.to_s
42
- @salt_hash = Passwd.hashing(@salt_text)
43
- @hash = Passwd.hashing("#{@salt_hash}#{@text}")
44
- end
45
35
 
46
- def text=(password)
47
- @hash = Passwd.hashing("#{@salt_hash}#{password}")
48
- @text = password
49
- end
36
+ def text=(password)
37
+ @hash = Passwd.hashing("#{@salt_hash}#{password}")
38
+ @text = password
39
+ end
50
40
 
51
- def hash=(password_hash)
52
- @text = nil
53
- @hash = password_hash
54
- end
41
+ def hash=(password_hash)
42
+ @text = nil
43
+ @hash = password_hash
44
+ end
55
45
 
56
- def salt_text=(salt_text)
57
- @salt_hash = Passwd.hashing(salt_text)
58
- @hash = Passwd.hashing("#{@salt_hash}#{@text}")
59
- @salt_text = salt_text
60
- end
46
+ def salt_text=(salt_text)
47
+ @salt_hash = Passwd.hashing(salt_text)
48
+ @hash = Passwd.hashing("#{@salt_hash}#{@text}")
49
+ @salt_text = salt_text
50
+ end
61
51
 
62
- def salt_hash=(salt_hash)
63
- @salt_text = nil
64
- @hash = Passwd.hashing("#{salt_hash}#{@text}")
65
- @salt_hash = salt_hash
66
- end
52
+ def salt_hash=(salt_hash)
53
+ @salt_text = nil
54
+ @hash = Passwd.hashing("#{salt_hash}#{@text}")
55
+ @salt_hash = salt_hash
56
+ end
67
57
 
68
- def policy_check
69
- Passwd.policy_check @text
70
- end
58
+ def policy_check
59
+ Passwd.policy_check @text
60
+ end
71
61
 
72
- def ==(password)
73
- enc_pass = Passwd.hashing("#{@salt_hash}#{password}")
74
- @hash == enc_pass
62
+ def ==(password)
63
+ enc_pass = Passwd.hashing("#{@salt_hash}#{password}")
64
+ @hash == enc_pass
65
+ end
75
66
  end
76
67
 
77
68
  class << self
@@ -1,3 +1,3 @@
1
- class Passwd
2
- VERSION = "0.0.3"
1
+ module Passwd
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/passwd_spec.rb CHANGED
@@ -140,10 +140,10 @@ describe Passwd do
140
140
  end
141
141
  end
142
142
 
143
- describe "instance methods" do
143
+ describe 'Password' do
144
144
  context "#initialize" do
145
145
  it "set instance valiables" do
146
- password = Passwd.new
146
+ password = Passwd::Password.new
147
147
  expect(password.text.size).to eq(8)
148
148
  expect(password.text.class).to eq(String)
149
149
  expect(password.hash.class).to eq(String)
@@ -153,34 +153,34 @@ describe Passwd do
153
153
 
154
154
  it "@text is specified password" do
155
155
  pass_text = Passwd.create
156
- password = Passwd.new(password: pass_text)
156
+ password = Passwd::Password.new(password: pass_text)
157
157
  expect(password.text).to eq(pass_text)
158
158
  end
159
159
 
160
160
  it "@hash is hash of specified password" do
161
161
  pass_text = Passwd.create
162
- password = Passwd.new(password: pass_text)
162
+ password = Passwd::Password.new(password: pass_text)
163
163
  pass_hash = Passwd.hashing("#{password.salt_hash}#{pass_text}")
164
164
  expect(password.hash).to eq(pass_hash)
165
165
  end
166
166
 
167
167
  it "@salt_text is specified salt" do
168
168
  salt_text = "salt"
169
- password = Passwd.new(salt_text: salt_text)
169
+ password = Passwd::Password.new(salt_text: salt_text)
170
170
  expect(password.salt_text).to eq(salt_text)
171
171
  end
172
172
 
173
173
  it "@salt_hash is hash of specified salt" do
174
174
  salt_text = "salt"
175
175
  salt_hash = Passwd.hashing(salt_text)
176
- password = Passwd.new(salt_text: salt_text)
176
+ password = Passwd::Password.new(salt_text: salt_text)
177
177
  expect(password.salt_hash).to eq(salt_hash)
178
178
  end
179
179
  end
180
180
 
181
181
  context "#text=" do
182
182
  before(:each) do
183
- @password = Passwd.new(password: "Secret!!")
183
+ @password = Passwd::Password.new(password: "Secret!!")
184
184
  end
185
185
 
186
186
  it "@text is changed" do
@@ -198,7 +198,7 @@ describe Passwd do
198
198
 
199
199
  context "#hash=" do
200
200
  before(:each) do
201
- @password = Passwd.new
201
+ @password = Passwd::Password.new
202
202
  end
203
203
 
204
204
  it "@text is nil" do
@@ -215,7 +215,7 @@ describe Passwd do
215
215
 
216
216
  context "#salt_text=" do
217
217
  before(:each) do
218
- @password = Passwd.new
218
+ @password = Passwd::Password.new
219
219
  end
220
220
 
221
221
  it "@salt_text is changed" do
@@ -239,7 +239,7 @@ describe Passwd do
239
239
 
240
240
  context "#salt_hash=" do
241
241
  before(:each) do
242
- @password = Passwd.new
242
+ @password = Passwd::Password.new
243
243
  end
244
244
 
245
245
  it "@salt_text is nil" do
@@ -264,14 +264,14 @@ describe Passwd do
264
264
  it "Passwd.policy_check is called with pass_text" do
265
265
  pass_text = Passwd.create
266
266
  Passwd.should_receive(:policy_check).with(pass_text)
267
- password = Passwd.new(password: pass_text)
267
+ password = Passwd::Password.new(password: pass_text)
268
268
  password.policy_check
269
269
  end
270
270
  end
271
271
 
272
272
  context "#==" do
273
273
  before(:each) do
274
- @password = Passwd.new
274
+ @password = Passwd::Password.new
275
275
  end
276
276
 
277
277
  it "return true with valid password" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passwd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  segments:
92
92
  - 0
93
- hash: -2718541000702937110
93
+ hash: 2599599372076087466
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
@@ -99,10 +99,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  segments:
101
101
  - 0
102
- hash: -2718541000702937110
102
+ hash: 2599599372076087466
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 1.8.25
105
+ rubygems_version: 1.8.23
106
106
  signing_key:
107
107
  specification_version: 3
108
108
  summary: Password utility