pwm 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pwm +6 -1
- data/lib/pwm.rb +12 -7
- data/lib/pwm/version.rb +1 -1
- data/spec/pwm_spec.rb +14 -2
- metadata +2 -2
data/bin/pwm
CHANGED
data/lib/pwm.rb
CHANGED
@@ -13,7 +13,7 @@ module Pwm
|
|
13
13
|
|
14
14
|
# Public: Generate a password.
|
15
15
|
#
|
16
|
-
# length - The length of the password.
|
16
|
+
# length - The length of the password. Minimum is 8. Default is 16.
|
17
17
|
#
|
18
18
|
# Examples
|
19
19
|
#
|
@@ -23,14 +23,19 @@ module Pwm
|
|
23
23
|
# Pwm.password(8)
|
24
24
|
# # => 'oUX4fmqr'
|
25
25
|
#
|
26
|
-
# Returns the generated password as a String
|
26
|
+
# Returns the generated password as a String if length >= 8,
|
27
|
+
# or nil is length < 8.
|
27
28
|
def self.password(length = 16)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
if length < 8
|
30
|
+
nil
|
31
|
+
else
|
32
|
+
password = ''
|
33
|
+
until (password.match(/[A-Z]/) && password.match(/[a-z]/) && password.match(/[0-9]/))
|
34
|
+
password = (0..length - 1).inject('') do |pw, n|
|
35
|
+
pw + characters[rand(characters.length)]
|
36
|
+
end
|
32
37
|
end
|
38
|
+
password
|
33
39
|
end
|
34
|
-
password
|
35
40
|
end
|
36
41
|
end
|
data/lib/pwm/version.rb
CHANGED
data/spec/pwm_spec.rb
CHANGED
@@ -26,8 +26,20 @@ describe Pwm do
|
|
26
26
|
|
27
27
|
context 'The password method' do
|
28
28
|
context 'when given a length' do
|
29
|
-
|
30
|
-
|
29
|
+
context 'equal to 8' do
|
30
|
+
it 'generates a password of that length' do
|
31
|
+
Pwm.password(8).length.should == 8
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context 'greater than 8' do
|
35
|
+
it 'generates a password of that length' do
|
36
|
+
Pwm.password(9).length.should == 9
|
37
|
+
end
|
38
|
+
end
|
39
|
+
context 'less than 8' do
|
40
|
+
it 'does not generate a password' do
|
41
|
+
Pwm.password(7).should be_nil
|
42
|
+
end
|
31
43
|
end
|
32
44
|
end
|
33
45
|
context 'when not given a length' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pwm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
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: 2012-09-
|
12
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|