passwd 0.0.5 → 0.0.6
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/.coveralls.yml +1 -0
- data/Gemfile +4 -0
- data/README.md +3 -25
- data/lib/passwd.rb +7 -44
- data/lib/passwd/password.rb +0 -4
- data/lib/passwd/version.rb +1 -1
- data/spec/passwd/password_spec.rb +0 -9
- data/spec/passwd_spec.rb +0 -55
- data/spec/spec_helper.rb +3 -0
- metadata +5 -4
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: juJNf3K7FF93l6tzdF8cv1V2NFgGdCaWv
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Passwd
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/passwd)
|
3
4
|
[](https://travis-ci.org/i2bskn/passwd)
|
5
|
+
[](https://codeclimate.com/github/i2bskn/passwd)
|
6
|
+
[](https://coveralls.io/r/i2bskn/passwd?branch=master)
|
4
7
|
|
5
8
|
Password utilities.
|
6
9
|
|
@@ -60,31 +63,6 @@ Options that can be specified:
|
|
60
63
|
* :letters_upper => Define an array of upper case. default is ("A".."Z").to_a
|
61
64
|
* :letters_number => Define an array of numbers. default is ("0".."9").to_a
|
62
65
|
|
63
|
-
### Password policy check
|
64
|
-
|
65
|
-
```ruby
|
66
|
-
Passwd.policy_check(password)
|
67
|
-
```
|
68
|
-
|
69
|
-
### Policy settings
|
70
|
-
|
71
|
-
Default policy is stored in the class variable. (@@policy)
|
72
|
-
Changing the default policy are as follows:
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
Passwd.policy => Get policy hash.
|
76
|
-
Passwd.policy(min_length: 10) => Change to the default min_length.
|
77
|
-
```
|
78
|
-
|
79
|
-
Options that can be specified:
|
80
|
-
|
81
|
-
* :min_length => Minimum length of password. default is 8.
|
82
|
-
* :min_type => Minimum types of password. default is 2.(types is lower/upper/number)
|
83
|
-
* :specify_type => Check of each types. default is false.
|
84
|
-
* :require_lower => Require lower case if set true. specify_type enabled when true.
|
85
|
-
* :require_upper => Require upper case if set true. specify_type enabled when true.
|
86
|
-
* :require_number => Require number case if set true. specify_type enabled when true.
|
87
|
-
|
88
66
|
### Password object
|
89
67
|
|
90
68
|
Default password is randomly generated.
|
data/lib/passwd.rb
CHANGED
@@ -17,55 +17,22 @@ module Passwd
|
|
17
17
|
letters_number: ('0'..'9').to_a
|
18
18
|
}
|
19
19
|
|
20
|
-
@@policy = {
|
21
|
-
min_length: 8,
|
22
|
-
min_type: 2,
|
23
|
-
specify_type: false,
|
24
|
-
require_lower: true,
|
25
|
-
require_upper: true,
|
26
|
-
require_number: true
|
27
|
-
}
|
28
|
-
|
29
20
|
class << self
|
30
21
|
def create(options={})
|
31
22
|
config = @@config.merge(options)
|
23
|
+
letters = get_retters(config)
|
32
24
|
|
25
|
+
# Create random password
|
26
|
+
Array.new(config[:length]){letters[rand(letters.size)]}.join
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_retters(config)
|
33
30
|
# Create letters
|
34
31
|
letters = Array.new
|
35
32
|
letters += config[:letters_lower] if config[:lower]
|
36
33
|
letters += config[:letters_upper] if config[:upper]
|
37
34
|
letters += config[:letters_number] if config[:number]
|
38
|
-
|
39
|
-
# Create random password
|
40
|
-
Array.new(config[:length]){letters[rand(letters.size)]}.join
|
41
|
-
end
|
42
|
-
|
43
|
-
def policy_check(passwd, options={})
|
44
|
-
policy = @@policy.merge(options)
|
45
|
-
|
46
|
-
# Check number of characters
|
47
|
-
return false if passwd.size < policy[:min_length]
|
48
|
-
|
49
|
-
# Check number of types of characters
|
50
|
-
ctype = Array.new
|
51
|
-
passwd.each_char.with_index do |char, i|
|
52
|
-
case
|
53
|
-
when @@config[:letters_lower].include?(char) then ctype << 0
|
54
|
-
when @@config[:letters_upper].include?(char) then ctype << 1
|
55
|
-
when @@config[:letters_number].include?(char) then ctype << 2
|
56
|
-
end
|
57
|
-
end
|
58
|
-
ctype.uniq!
|
59
|
-
return false if ctype.size < policy[:min_type]
|
60
|
-
|
61
|
-
# Check of each character type
|
62
|
-
if policy[:specify_type]
|
63
|
-
return false if policy[:require_lower] && !ctype.include?(0)
|
64
|
-
return false if policy[:require_upper] && !ctype.include?(1)
|
65
|
-
return false if policy[:require_number] && !ctype.include?(2)
|
66
|
-
end
|
67
|
-
|
68
|
-
true
|
35
|
+
letters
|
69
36
|
end
|
70
37
|
|
71
38
|
def auth(password_text, salt_hash, password_hash)
|
@@ -80,9 +47,5 @@ module Passwd
|
|
80
47
|
def config(options={})
|
81
48
|
@@config.merge!(options)
|
82
49
|
end
|
83
|
-
|
84
|
-
def policy(options={})
|
85
|
-
@@policy.merge!(options)
|
86
|
-
end
|
87
50
|
end
|
88
51
|
end
|
data/lib/passwd/password.rb
CHANGED
data/lib/passwd/version.rb
CHANGED
@@ -122,15 +122,6 @@ describe Passwd::Password do
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
context "#policy_check" do
|
126
|
-
it "Passwd.policy_check is called with pass_text" do
|
127
|
-
pass_text = Passwd.create
|
128
|
-
Passwd.should_receive(:policy_check).with(pass_text)
|
129
|
-
password = Passwd::Password.new(password: pass_text)
|
130
|
-
password.policy_check
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
125
|
context "#==" do
|
135
126
|
before(:each) do
|
136
127
|
@password = Passwd::Password.new
|
data/spec/passwd_spec.rb
CHANGED
@@ -33,41 +33,6 @@ describe Passwd do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context "#policy_check" do
|
37
|
-
it "return true with valid password" do
|
38
|
-
expect(Passwd.policy_check("09aVCud5")).to eq(true)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "return false with less number of characters" do
|
42
|
-
expect(Passwd.policy_check("Secret")).to eq(false)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "return false with less number of types" do
|
46
|
-
expect(Passwd.policy_check("password")).to eq(false)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "require lower case if require_lower is true" do
|
50
|
-
password = Passwd.create(lower: false)
|
51
|
-
expect(
|
52
|
-
Passwd.policy_check(password, min_type: 1, specify_type: true, require_lower: true)
|
53
|
-
).to eq(false)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "require upper case if require_upper is true" do
|
57
|
-
password = Passwd.create(upper: false)
|
58
|
-
expect(
|
59
|
-
Passwd.policy_check(password, min_type: 1, specify_type: true, require_upper: true)
|
60
|
-
).to eq(false)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "require number case if require_number is true" do
|
64
|
-
password = Passwd.create(number: false)
|
65
|
-
expect(
|
66
|
-
Passwd.policy_check(password, min_type: 1, specify_type: true, require_number: true)
|
67
|
-
).to eq(false)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
36
|
context "#auth" do
|
72
37
|
it "return true with valid password" do
|
73
38
|
password = Passwd.create
|
@@ -115,25 +80,5 @@ describe Passwd do
|
|
115
80
|
expect(Passwd.config[:length]).not_to eq(old_value)
|
116
81
|
end
|
117
82
|
end
|
118
|
-
|
119
|
-
context "#policy" do
|
120
|
-
before(:all) do
|
121
|
-
@default_value = Passwd.policy.clone
|
122
|
-
end
|
123
|
-
|
124
|
-
after(:all) do
|
125
|
-
Passwd.policy(@default_value)
|
126
|
-
end
|
127
|
-
|
128
|
-
it "return policy hash" do
|
129
|
-
expect(Passwd.policy.class).to eq(Hash)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "set config value" do
|
133
|
-
old_value = Passwd.policy[:min_length]
|
134
|
-
Passwd.policy(min_length: 10)
|
135
|
-
expect(Passwd.policy[:min_length]).not_to eq(old_value)
|
136
|
-
end
|
137
|
-
end
|
138
83
|
end
|
139
84
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -66,6 +66,7 @@ executables: []
|
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
|
+
- .coveralls.yml
|
69
70
|
- .gitignore
|
70
71
|
- .travis.yml
|
71
72
|
- Gemfile
|
@@ -96,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
97
|
version: '0'
|
97
98
|
segments:
|
98
99
|
- 0
|
99
|
-
hash:
|
100
|
+
hash: -540825171026277875
|
100
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
102
|
none: false
|
102
103
|
requirements:
|
@@ -105,10 +106,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
version: '0'
|
106
107
|
segments:
|
107
108
|
- 0
|
108
|
-
hash:
|
109
|
+
hash: -540825171026277875
|
109
110
|
requirements: []
|
110
111
|
rubyforge_project:
|
111
|
-
rubygems_version: 1.8.
|
112
|
+
rubygems_version: 1.8.23
|
112
113
|
signing_key:
|
113
114
|
specification_version: 3
|
114
115
|
summary: Password utility
|