passwd 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -4
- data/lib/passwd/base.rb +6 -0
- data/lib/passwd/version.rb +1 -1
- data/samples/activerecord/user.rake +28 -0
- data/spec/passwd/base_spec.rb +22 -0
- data/spec/spec_helper.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcb00a834c359109c28cbe26c845b8baa2ec93b7
|
4
|
+
data.tar.gz: 07cff7e7538f4f59889fecad96ab0715edd9ee05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc8ac70bace4de95e9ae1d9d6f05b16843b1c27d3c2af09b748c38100db9f79105a991da929a387b9bf76733b57a7885d98238fccc27f9b7b9b5ca5bd5af804b
|
7
|
+
data.tar.gz: b53e2c20abb856f932de3612a63f0cde50d6d7498ec233b7bc2a3652899c6420d63801ee5e1901c1adf7b32b0a9c6a5040f462d4ce3ab7ac21cce4dc0f20d1f9
|
data/README.md
CHANGED
@@ -185,13 +185,16 @@ Return the nil if authentication fails.
|
|
185
185
|
But `update_password` method doesn't call `save` method.
|
186
186
|
|
187
187
|
```ruby
|
188
|
-
user.find(params[:id])
|
189
|
-
|
190
|
-
|
188
|
+
@user = User.find(params[:id])
|
189
|
+
|
190
|
+
if Passwd.confirm_check(params[:new_pass], params[:new_pass_confirm])
|
191
|
+
if @user.update_password(old_pass, new_pass) && @user.save # => return new password(text) or false
|
191
192
|
NoticeMailer.change_mail(user, password_text).deliver
|
193
|
+
else
|
194
|
+
puts "Authentication failed!"
|
192
195
|
end
|
193
196
|
else
|
194
|
-
puts "
|
197
|
+
puts "Password don't match!"
|
195
198
|
end
|
196
199
|
```
|
197
200
|
|
data/lib/passwd/base.rb
CHANGED
@@ -28,6 +28,12 @@ module Passwd
|
|
28
28
|
Digest::SHA1.hexdigest plain
|
29
29
|
end
|
30
30
|
|
31
|
+
def confirm_check(password, confirm, with_policy=false)
|
32
|
+
return false if password != confirm
|
33
|
+
return true unless with_policy
|
34
|
+
Passwd.policy_check(password)
|
35
|
+
end
|
36
|
+
|
31
37
|
def configure(options={}, &block)
|
32
38
|
if block_given?
|
33
39
|
@config.configure &block
|
data/lib/passwd/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
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
|
data/spec/passwd/base_spec.rb
CHANGED
@@ -79,6 +79,28 @@ describe Passwd do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
describe "#confirm_check" do
|
83
|
+
context "with out policy check" do
|
84
|
+
it "return false if password don't match" do
|
85
|
+
expect(Passwd.confirm_check("secret", "invalid")).to be_false
|
86
|
+
end
|
87
|
+
|
88
|
+
it "return true if password matches" do
|
89
|
+
expect(Passwd.confirm_check("secret", "secret")).to be_true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "with policy check" do
|
94
|
+
it "return false if invalid password by policy" do
|
95
|
+
expect(Passwd.confirm_check("secret", "secret", true)).to be_false
|
96
|
+
end
|
97
|
+
|
98
|
+
it "return true if valid password by policy" do
|
99
|
+
expect(Passwd.confirm_check("secretpass", "secretpass", true)).to be_false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
82
104
|
describe "#configure" do
|
83
105
|
it "return configuration object" do
|
84
106
|
expect(Passwd.configure.is_a? Passwd::Config).to be_true
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,11 @@ require "simplecov"
|
|
2
2
|
require "coveralls"
|
3
3
|
Coveralls.wear!
|
4
4
|
|
5
|
-
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
|
6
10
|
SimpleCov.start do
|
7
11
|
add_filter "spec"
|
8
12
|
add_filter ".bundle"
|
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.3
|
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-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/passwd/password.rb
|
77
77
|
- lib/passwd/version.rb
|
78
78
|
- passwd.gemspec
|
79
|
+
- samples/activerecord/user.rake
|
79
80
|
- spec/passwd/active_record_spec.rb
|
80
81
|
- spec/passwd/base_spec.rb
|
81
82
|
- spec/passwd/configuration/config_spec.rb
|