passwd 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +32 -18
- data/Rakefile +1 -1
- data/lib/passwd.rb +1 -0
- data/lib/passwd/base.rb +6 -2
- data/lib/passwd/configuration/abstract_config.rb +1 -0
- data/lib/passwd/configuration/config.rb +1 -0
- data/lib/passwd/version.rb +1 -1
- data/spec/passwd/active_record_spec.rb +2 -2
- data/spec/passwd/base_spec.rb +12 -2
- data/spec/passwd/configuration/config_spec.rb +8 -0
- data/spec/passwd/configuration/tmp_config_spec.rb +8 -0
- metadata +4 -4
- data/samples/activerecord/user.rake +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a606e91758a61195dc7a2f4a82a16ce1d845c68e
|
4
|
+
data.tar.gz: 70f0ece850a255a83972a3ac47c4eb3a6a994a1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cd8cd9771d2252d9c0123da43ac2324fcd7d33cb194accb5bff78c4732d7713d61d7b8556513a6b4a747aeb14e35473d873d3731f0ad9e4cfad56347bd98fb2
|
7
|
+
data.tar.gz: 9a78a83972cbf53c3a8ded6caa0ee7e84b58d0598c3a8b368d710ead163e63b1e114d4ecb47bd2d91b29f151845c4cee4ea391fb0b86aa7b2961390cae92100b
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -53,12 +53,14 @@ Passwd.config # => Get config object.
|
|
53
53
|
Passwd.config(length: 10) # => Change to the default length.
|
54
54
|
|
55
55
|
Passwd.configure do |c|
|
56
|
+
c.algorithm = :sha512
|
56
57
|
c.length = 10
|
57
58
|
end
|
58
59
|
```
|
59
60
|
|
60
61
|
Options that can be specified:
|
61
62
|
|
63
|
+
* :algorithm => Hashing algorithm. default is :sha512.
|
62
64
|
* :length => Number of characters. default is 8.
|
63
65
|
* :lower => Skip lower case if set false. default is true.
|
64
66
|
* :upper => Skip upper case if set false. default is true.
|
@@ -145,23 +147,28 @@ Return the user object if the authentication successful.
|
|
145
147
|
Return the nil if authentication fails or doesn't exists user.
|
146
148
|
|
147
149
|
```ruby
|
148
|
-
user = User.authenticate(
|
150
|
+
user = User.authenticate(params[:email], params[:password]) # => return user object or nil.
|
149
151
|
|
150
152
|
if user
|
151
|
-
|
153
|
+
session[:user] = user.id
|
154
|
+
redirect_to bar_path, notice: "Hello #{user.name}!"
|
152
155
|
else
|
153
|
-
|
156
|
+
flash.now[:alert] = "Authentication failed"
|
157
|
+
render action: :new
|
154
158
|
end
|
155
159
|
```
|
156
160
|
|
157
161
|
instance method is not required `id`.
|
158
162
|
|
159
163
|
```ruby
|
160
|
-
|
161
|
-
|
162
|
-
|
164
|
+
current_user = User.find(session[:user])
|
165
|
+
|
166
|
+
if current_user.authenticate(params[:password]) # => return true or false
|
167
|
+
# some process
|
168
|
+
redirect_to bar_path, notice: "Some process is successfully"
|
163
169
|
else
|
164
|
-
|
170
|
+
flash.now[:alert] = "Authentication failed"
|
171
|
+
render action: :edit
|
165
172
|
end
|
166
173
|
```
|
167
174
|
|
@@ -173,11 +180,13 @@ To specify the password as an argument if you want to specify a password.
|
|
173
180
|
`salt` also set if salt is nil.
|
174
181
|
|
175
182
|
```ruby
|
176
|
-
|
177
|
-
password_text =
|
183
|
+
current_user = User.find(session[:user])
|
184
|
+
password_text = current_user.set_password
|
178
185
|
|
179
|
-
if
|
180
|
-
|
186
|
+
if current_user.save
|
187
|
+
redirect_to bar_path, notice: "Password update successfully"
|
188
|
+
else
|
189
|
+
render action: :edit
|
181
190
|
end
|
182
191
|
```
|
183
192
|
|
@@ -185,23 +194,28 @@ end
|
|
185
194
|
But `update_password` method doesn't call `save` method.
|
186
195
|
|
187
196
|
```ruby
|
188
|
-
|
197
|
+
current_user = User.find(session[:user])
|
189
198
|
|
190
199
|
begin
|
191
|
-
confirm_check(
|
192
|
-
|
193
|
-
|
200
|
+
Passwd.confirm_check(params[:password], params[:password_confirmation])
|
201
|
+
# update_password(OLD_PASSWORD, NEW_PASSWORD[, POLICY_CHECK=false])
|
202
|
+
current_user.update_password(old_pass, new_pass, true)
|
203
|
+
current_user.save!
|
194
204
|
redirect_to bar_path, notice: "Password updated successfully"
|
195
|
-
rescue PasswordNotMatch
|
205
|
+
rescue Passwd::PasswordNotMatch
|
206
|
+
# PASSWORD != PASSWORD_CONFIRMATION from Passwd.#confirm_check
|
196
207
|
flash.now[:alert] = "Password not match"
|
197
208
|
render action: :edit
|
198
|
-
rescue AuthError
|
209
|
+
rescue Passwd::AuthError
|
210
|
+
# Authentication failed from #update_password
|
199
211
|
flash.now[:alert] = "Password is incorrect"
|
200
212
|
render action: :edit
|
201
|
-
rescue PolicyNotMatch
|
213
|
+
rescue Passwd::PolicyNotMatch
|
214
|
+
# Policy not match from #update_password
|
202
215
|
flash.now[:alert] = "Policy not match"
|
203
216
|
render action: :edit
|
204
217
|
rescue
|
218
|
+
# Other errors
|
205
219
|
flash.now[:alert] = "Password update failed"
|
206
220
|
render action: :edit
|
207
221
|
end
|
data/Rakefile
CHANGED
data/lib/passwd.rb
CHANGED
data/lib/passwd/base.rb
CHANGED
@@ -24,8 +24,12 @@ module Passwd
|
|
24
24
|
password_hash == enc_pass
|
25
25
|
end
|
26
26
|
|
27
|
-
def hashing(plain)
|
28
|
-
|
27
|
+
def hashing(plain, algorithm=nil)
|
28
|
+
if algorithm.nil?
|
29
|
+
eval "Digest::#{@config.algorithm.to_s.upcase}.hexdigest \"#{plain}\""
|
30
|
+
else
|
31
|
+
eval "Digest::#{algorithm.to_s.upcase}.hexdigest \"#{plain}\""
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def confirm_check(password, confirm, with_policy=false)
|
data/lib/passwd/version.rb
CHANGED
@@ -8,9 +8,9 @@ describe Passwd::ActiveRecord do
|
|
8
8
|
define_column
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:salt) {Digest::
|
11
|
+
let(:salt) {Digest::SHA512.hexdigest("salt")}
|
12
12
|
let(:password_text) {"secret"}
|
13
|
-
let(:password_hash) {Digest::
|
13
|
+
let(:password_hash) {Digest::SHA512.hexdigest("#{salt}#{password_text}")}
|
14
14
|
|
15
15
|
describe ".#included" do
|
16
16
|
it "define singleton methods" do
|
data/spec/passwd/base_spec.rb
CHANGED
@@ -69,9 +69,19 @@ describe Passwd do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
describe "#hashing" do
|
72
|
+
it "should call SHA512.#hexdigest" do
|
73
|
+
Digest::SHA512.should_receive(:hexdigest)
|
74
|
+
Passwd.hashing("secret")
|
75
|
+
end
|
76
|
+
|
72
77
|
it "return hashed password" do
|
73
|
-
Digest::
|
74
|
-
expect(Passwd.hashing("secret")).to eq(
|
78
|
+
hashed = Digest::SHA512.hexdigest "secret"
|
79
|
+
expect(Passwd.hashing("secret")).to eq(hashed)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "return hashed password specified algorithm" do
|
83
|
+
hashed = Digest::SHA256.hexdigest "secret"
|
84
|
+
expect(Passwd.hashing("secret", :sha256)).to eq(hashed)
|
75
85
|
end
|
76
86
|
|
77
87
|
it "should create exception if not specified argument" do
|
@@ -6,6 +6,10 @@ describe Passwd::Config do
|
|
6
6
|
let(:config) {Passwd::Config.instance}
|
7
7
|
|
8
8
|
describe "defined accessors" do
|
9
|
+
it "defined algorithm" do
|
10
|
+
expect(config.respond_to? :algorithm).to be_true
|
11
|
+
end
|
12
|
+
|
9
13
|
it "defined length" do
|
10
14
|
expect(config.respond_to? :length).to be_true
|
11
15
|
end
|
@@ -36,6 +40,10 @@ describe Passwd::Config do
|
|
36
40
|
end
|
37
41
|
|
38
42
|
describe "#initialize" do
|
43
|
+
it "algorithm should be a default" do
|
44
|
+
expect(config.algorithm).to eq(:sha512)
|
45
|
+
end
|
46
|
+
|
39
47
|
it "length should be a default" do
|
40
48
|
expect(config.length).to eq(8)
|
41
49
|
end
|
@@ -10,6 +10,10 @@ describe Passwd::TmpConfig do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "defined accessors" do
|
13
|
+
it "defined algorithm" do
|
14
|
+
expect(config.respond_to? :algorithm).to be_true
|
15
|
+
end
|
16
|
+
|
13
17
|
it "defined length" do
|
14
18
|
expect(tmp_config.respond_to? :length).to be_true
|
15
19
|
end
|
@@ -41,6 +45,10 @@ describe Passwd::TmpConfig do
|
|
41
45
|
|
42
46
|
describe "#initialize" do
|
43
47
|
context "with empty options" do
|
48
|
+
it "algorithm should be a default" do
|
49
|
+
expect(config.algorithm).to eq(:sha512)
|
50
|
+
end
|
51
|
+
|
44
52
|
it "length should be a default" do
|
45
53
|
expect(tmp_config.length).to eq(8)
|
46
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passwd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- .coveralls.yml
|
63
63
|
- .gitignore
|
64
64
|
- .travis.yml
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
@@ -77,7 +78,6 @@ files:
|
|
77
78
|
- lib/passwd/password.rb
|
78
79
|
- lib/passwd/version.rb
|
79
80
|
- passwd.gemspec
|
80
|
-
- samples/activerecord/user.rake
|
81
81
|
- spec/passwd/active_record_spec.rb
|
82
82
|
- spec/passwd/base_spec.rb
|
83
83
|
- spec/passwd/configuration/config_spec.rb
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.0.
|
108
|
+
rubygems_version: 2.0.3
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Password utility
|
@@ -1,28 +0,0 @@
|
|
1
|
-
namespace :user do
|
2
|
-
# E.G. rake name="Taro Suzuki" email=taro@example.com password=secret user:create
|
3
|
-
desc "create user (specify env of name and email and password)"
|
4
|
-
task :create => :environment do
|
5
|
-
raise ArgumentError, "email is required" if ENV["email"].nil?
|
6
|
-
raise ArgumentError, "name is required" if ENV["name"].nil?
|
7
|
-
|
8
|
-
raise "must be a unique email" if User.exists?(email: ENV["email"])
|
9
|
-
|
10
|
-
user = User.new(name: ENV["name"], email: ENV["email"])
|
11
|
-
|
12
|
-
password = user.set_password(ENV["password"])
|
13
|
-
user.save!
|
14
|
-
puts "Creating a user was successful.\nPassword: #{password}"
|
15
|
-
end
|
16
|
-
|
17
|
-
# E.G. rake email=taro@example.com password=secret user:password_update
|
18
|
-
desc "update password (specify env of email and password)"
|
19
|
-
task :password_update => :environment do
|
20
|
-
raise ArgumentError, "email is required" if ENV["email"].nil?
|
21
|
-
raise "must specify the email that exists" unless User.exists?(email: ENV["email"])
|
22
|
-
|
23
|
-
user = User.find_by(email: ENV["email"])
|
24
|
-
password = user.set_password(ENV["password"])
|
25
|
-
user.save!
|
26
|
-
puts "Password update was successful.\nPassword: #{password}"
|
27
|
-
end
|
28
|
-
end
|